Skip to content

Commit 53b808f

Browse files
authored
Merge pull request #2118 from abeln/super-bug
Fix #2117: bug in typechecking super prefix with invalid enclosing class
2 parents 8c26743 + 3920414 commit 53b808f

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

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

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -291,26 +291,28 @@ trait TypeAssigner {
291291

292292
def assignType(tree: untpd.Super, qual: Tree, inConstrCall: Boolean, mixinClass: Symbol = NoSymbol)(implicit ctx: Context) = {
293293
val mix = tree.mix
294-
val qtype @ ThisType(_) = qual.tpe
295-
val cls = qtype.cls
296-
297-
def findMixinSuper(site: Type): Type = site.parents filter (_.name == mix.name) match {
298-
case p :: Nil =>
299-
p
300-
case Nil =>
301-
errorType(SuperQualMustBeParent(mix, cls), tree.pos)
302-
case p :: q :: _ =>
303-
errorType("ambiguous parent class qualifier", tree.pos)
294+
qual.tpe match {
295+
case err: ErrorType => untpd.cpy.Super(tree)(qual, mix).withType(err)
296+
case qtype @ ThisType(_) =>
297+
val cls = qtype.cls
298+
def findMixinSuper(site: Type): Type = site.parents filter (_.name == mix.name) match {
299+
case p :: Nil =>
300+
p
301+
case Nil =>
302+
errorType(SuperQualMustBeParent(mix, cls), tree.pos)
303+
case p :: q :: _ =>
304+
errorType("ambiguous parent class qualifier", tree.pos)
305+
}
306+
val owntype =
307+
if (mixinClass.exists) mixinClass.typeRef
308+
else if (!mix.isEmpty) findMixinSuper(cls.info)
309+
else if (inConstrCall || ctx.erasedTypes) cls.info.firstParent
310+
else {
311+
val ps = cls.classInfo.parentsWithArgs
312+
if (ps.isEmpty) defn.AnyType else ps.reduceLeft((x: Type, y: Type) => x & y)
313+
}
314+
tree.withType(SuperType(cls.thisType, owntype))
304315
}
305-
val owntype =
306-
if (mixinClass.exists) mixinClass.typeRef
307-
else if (!mix.isEmpty) findMixinSuper(cls.info)
308-
else if (inConstrCall || ctx.erasedTypes) cls.info.firstParent
309-
else {
310-
val ps = cls.classInfo.parentsWithArgs
311-
if (ps.isEmpty) defn.AnyType else ps.reduceLeft((x: Type, y: Type) => x & y)
312-
}
313-
tree.withType(SuperType(cls.thisType, owntype))
314316
}
315317

316318
def assignType(tree: untpd.Apply, fn: Tree, args: List[Tree])(implicit ctx: Context) = {

tests/neg/i2117.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class A {
2+
C.super.foo() // error: C isn't an enclosing class
3+
}

0 commit comments

Comments
 (0)