Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 18861cb

Browse files
tanishikingmichelou
authored andcommittedApr 25, 2022
refactor: TopLevel implicit is now allowed
It seems like TopLevelCantBeImplicit is no longer the case as of scala#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 2f64a01 commit 18861cb

File tree

2 files changed

+1
-9
lines changed

2 files changed

+1
-9
lines changed
 

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

-7
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

+1-2
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)
Please sign in to comment.