Skip to content

Commit 4e49976

Browse files
committed
Avoif follow-on errors for illegal implicit classes
Supporess creation of implicit factory if it would be illegal.
1 parent 3da5e04 commit 4e49976

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -380,18 +380,22 @@ object desugar {
380380
// synthetic implicit C[Ts](p11: T11, ..., p1N: T1N) ... (pM1: TM1, ..., pMN: TMN): C[Ts] =
381381
// new C[Ts](p11, ..., p1N) ... (pM1, ..., pMN) =
382382
val implicitWrappers =
383-
if (mods is Implicit) {
384-
if (ctx.owner is Package)
385-
ctx.error("implicit classes may not be toplevel", cdef.pos)
386-
if (mods is Case)
387-
ctx.error("implicit classes may not case classes", cdef.pos)
388-
383+
if (!mods.is(Implicit))
384+
Nil
385+
else if (ctx.owner is Package) {
386+
ctx.error("implicit classes may not be toplevel", cdef.pos)
387+
Nil
388+
}
389+
else if (mods is Case) {
390+
ctx.error("implicit classes may not be case classes", cdef.pos)
391+
Nil
392+
}
393+
else
389394
// implicit wrapper is typechecked in same scope as constructor, so
390395
// we can reuse the constructor parameters; no derived params are needed.
391396
DefDef(name.toTermName, constrTparams, constrVparamss, classTypeRef, creatorExpr)
392397
.withFlags(Synthetic | Implicit) :: Nil
393-
}
394-
else Nil
398+
395399

396400
val self1 = {
397401
val selfType = if (self.tpt.isEmpty) classTypeRef else self.tpt

0 commit comments

Comments
 (0)