Skip to content

Commit 127083b

Browse files
committed
Fix exception in super resolution
1 parent e87660a commit 127083b

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

compiler/src/dotty/tools/dotc/transform/init/Checking.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ object Checking {
278278
val target = resolveSuper(cls, supercls, sym)
279279
if (!target.is(Flags.Method))
280280
check(FieldAccess(pot, target)(eff.source))
281-
if (target.isInternal) {
281+
else if (target.isInternal) {
282282
val effs = thisRef.effectsOf(target)
283283
effs.foreach { check(_) }
284284
}

compiler/src/dotty/tools/dotc/transform/init/Util.scala

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Contexts.Context
77
import Symbols._
88
import config.Printers.Printer
99

10+
import annotation.tailrec
1011

1112
object Util {
1213
def traceIndented(msg: String, printer: Printer)(implicit ctx: Context): Unit =
@@ -25,6 +26,16 @@ object Util {
2526
if (sym.isEffectivelyFinal || sym.isConstructor) sym
2627
else sym.matchingMember(cls.typeRef)
2728

28-
def resolveSuper(cls: ClassSymbol, superCls: ClassSymbol, sym: Symbol)(implicit ctx: Context): Symbol =
29-
sym.superSymbolIn(cls)
29+
def resolveSuper(cls: ClassSymbol, superCls: ClassSymbol, sym: Symbol)(implicit ctx: Context): Symbol = {
30+
// println(s"bases of $cls: " + cls.info.baseClasses)
31+
@tailrec def loop(bcs: List[ClassSymbol]): Symbol = bcs match {
32+
case bc :: bcs1 =>
33+
val cand = sym.matchingDecl(bcs.head, cls.thisType)
34+
.suchThat(alt => !alt.is(Flags.Deferred)).symbol
35+
if (cand.exists) cand else loop(bcs.tail)
36+
case _ =>
37+
NoSymbol
38+
}
39+
loop(cls.info.baseClasses.dropWhile(sym.owner != _))
40+
}
3041
}

tests/init/pos/super1.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import scala.collection.mutable
2+
3+
class Foo {
4+
private val map: mutable.Map[Int, String] = mutable.Map.empty
5+
6+
def enter(k: Int, v: String) = map(k) = v
7+
}
8+
9+
class Bar extends Foo {
10+
override def enter(k: Int, v: String) = ???
11+
def enterSuper(k: Int, v: String) = super.enter(k, v)
12+
13+
enter(1, "one")
14+
enterSuper(1, "one")
15+
super.enter(2, "two")
16+
}

0 commit comments

Comments
 (0)