From 6442498b1351b1e15c87e0353a5c4cc0cc948102 Mon Sep 17 00:00:00 2001 From: Rikito Taniguchi Date: Thu, 14 Apr 2022 18:35:47 +0900 Subject: [PATCH] refactor: TopLevel implicit is now allowed It seems like TopLevelCantBeImplicit is no longer the case as of https://github.com/lampepfl/dotty/pull/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. --- compiler/src/dotty/tools/dotc/reporting/messages.scala | 7 ------- compiler/src/dotty/tools/dotc/typer/Checking.scala | 3 +-- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/messages.scala b/compiler/src/dotty/tools/dotc/reporting/messages.scala index 18e2d234452d..c1545dadf46e 100644 --- a/compiler/src/dotty/tools/dotc/reporting/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/messages.scala @@ -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""" diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 1cce3fdea280..1e597e42d2a5 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -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()) }