Skip to content

Commit

Permalink
refactor: TopLevel implicit is now allowed
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tanishiking committed Apr 22, 2022
1 parent b636633 commit 6442498
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 9 deletions.
7 changes: 0 additions & 7 deletions compiler/src/dotty/tools/dotc/reporting/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1510,13 +1510,6 @@ import transform.SymUtils._
def explain = ""
}

class TopLevelCantBeImplicit(sym: Symbol)(
implicit ctx: Context)
extends SyntaxMsg(TopLevelCantBeImplicitID) {
def msg = em"""${hl("implicit")} modifier cannot be used for top-level definitions"""
def explain = ""
}

class TypesAndTraitsCantBeImplicit()(using Context)
extends SyntaxMsg(TypesAndTraitsCantBeImplicitID) {
def msg = em"""${hl("implicit")} modifier cannot be used for types or traits"""
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,7 @@ object Checking {
if sym.isInlineMethod && !sym.is(Deferred) && sym.allOverriddenSymbols.nonEmpty then
checkInlineOverrideParameters(sym)
if (sym.is(Implicit)) {
if (sym.owner.is(Package))
fail(TopLevelCantBeImplicit(sym))
assert(!sym.owner.is(Package), s"top-level implicit $sym should be wrapped by a package after typer")
if sym.isType && (!sym.isClass || sym.is(Trait)) then
fail(TypesAndTraitsCantBeImplicit())
}
Expand Down

0 comments on commit 6442498

Please sign in to comment.