Skip to content

Commit 4bc831c

Browse files
committed
Fix error message
The change of Implicit to be a common flag now caused some breakage, which this commit fixes.
1 parent 84e818a commit 4bc831c

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,10 @@ object desugar {
670670
ctx.error(TopLevelImplicitClass(cdef), cdef.sourcePos)
671671
Nil
672672
}
673+
else if (mods.is(Trait)) {
674+
ctx.error(TypesAndTraitsCantBeImplicit(), cdef.sourcePos)
675+
Nil
676+
}
673677
else if (isCaseClass) {
674678
ctx.error(ImplicitCaseClass(cdef), cdef.sourcePos)
675679
Nil
@@ -688,7 +692,7 @@ object desugar {
688692
// implicit wrapper is typechecked in same scope as constructor, so
689693
// we can reuse the constructor parameters; no derived params are needed.
690694
DefDef(className.toTermName, constrTparams, defParamss, classTypeRef, creatorExpr)
691-
.withMods(companionMods | mods.flags & ImplicitOrImplied | Synthetic | Final)
695+
.withMods(companionMods | mods.flags.toTermFlags & ImplicitOrImplied | Synthetic | Final)
692696
.withSpan(cdef.span) :: Nil
693697
}
694698

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,8 +1507,7 @@ object messages {
15071507
val explanation: String = ""
15081508
}
15091509

1510-
case class TypesAndTraitsCantBeImplicit(sym: Symbol)(
1511-
implicit ctx: Context)
1510+
case class TypesAndTraitsCantBeImplicit()(implicit ctx: Context)
15121511
extends Message(TypesAndTraitsCantBeImplicitID) {
15131512
val msg: String = hl"""${"implicit"} modifier cannot be used for types or traits"""
15141513
val kind: String = "Syntax"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ object Checking {
380380
if (sym.owner.is(Package))
381381
fail(TopLevelCantBeImplicit(sym))
382382
if (sym.isType)
383-
fail(TypesAndTraitsCantBeImplicit(sym))
383+
fail(TypesAndTraitsCantBeImplicit())
384384
}
385385
if (!sym.isClass && sym.is(Abstract))
386386
fail(OnlyClassesCanBeAbstract(sym))

compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,8 +715,7 @@ class ErrorMessagesTests extends ErrorMessagesTest {
715715
.expect { (ictx, messages) =>
716716
implicit val ctx: Context = ictx
717717
assertMessageCount(1, messages)
718-
val TypesAndTraitsCantBeImplicit(symbol) :: Nil = messages
719-
assertEquals("trait S", symbol.show)
718+
val TypesAndTraitsCantBeImplicit() :: Nil = messages
720719
}
721720

722721
@Test def onlyClassesCanBeAbstract =

0 commit comments

Comments
 (0)