Skip to content

Commit 6442498

Browse files
committed
refactor: TopLevel implicit is now allowed
It seems like TopLevelCantBeImplicit is no longer the case as of #5754 And it is actually confirmed in https://github.com/lampepfl/dotty/blob/93fc41fcb624df73cc12d52b79d518a30a778a7c/tests/run/toplevel-implicits/a.b.scala#L19-L21 This commit replace the unnecessary check in from Checking.scala to assertion and deleted the `ErrorMessage` definition for `TopLevelCantBeImplicit`. I'm leaving the `TopLevelCantBeImplicitID` in `ErrorMessageID.scala` so we don't screw up the error number.
1 parent b636633 commit 6442498

File tree

2 files changed

+1
-9
lines changed

2 files changed

+1
-9
lines changed

compiler/src/dotty/tools/dotc/reporting/messages.scala

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,13 +1510,6 @@ import transform.SymUtils._
15101510
def explain = ""
15111511
}
15121512

1513-
class TopLevelCantBeImplicit(sym: Symbol)(
1514-
implicit ctx: Context)
1515-
extends SyntaxMsg(TopLevelCantBeImplicitID) {
1516-
def msg = em"""${hl("implicit")} modifier cannot be used for top-level definitions"""
1517-
def explain = ""
1518-
}
1519-
15201513
class TypesAndTraitsCantBeImplicit()(using Context)
15211514
extends SyntaxMsg(TypesAndTraitsCantBeImplicitID) {
15221515
def msg = em"""${hl("implicit")} modifier cannot be used for types or traits"""

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,7 @@ object Checking {
473473
if sym.isInlineMethod && !sym.is(Deferred) && sym.allOverriddenSymbols.nonEmpty then
474474
checkInlineOverrideParameters(sym)
475475
if (sym.is(Implicit)) {
476-
if (sym.owner.is(Package))
477-
fail(TopLevelCantBeImplicit(sym))
476+
assert(!sym.owner.is(Package), s"top-level implicit $sym should be wrapped by a package after typer")
478477
if sym.isType && (!sym.isClass || sym.is(Trait)) then
479478
fail(TypesAndTraitsCantBeImplicit())
480479
}

0 commit comments

Comments
 (0)