Skip to content

Commit cd3aef2

Browse files
committed
Use lexicallyEnclosingClass instead of enclosingClass
enclosingClass returns a different report for module objects.
1 parent bfb395d commit cd3aef2

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ object Potentials {
109109
*/
110110
case class Outer(pot: Potential, classSymbol: ClassSymbol)(val source: Tree) extends Potential {
111111
def size: Int = 1 + pot.size
112-
def show(using Context): String = "Outer[" + pot.show + ", " + classSymbol.show + "]"
112+
def show(using Context): String = pot.show + ".outer[" + classSymbol.show + "]"
113113
}
114114

115115
/** The object pointed by `this.f` */

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ object Summarization {
220220
}
221221

222222
case ThisType(tref) =>
223-
val enclosing = env.ctx.owner.enclosingClass.asClass
223+
val enclosing = env.ctx.owner.lexicallyEnclosingClass.asClass
224224
val cls = tref.symbol.asClass
225225
resolveThis(cls, ThisRef()(source), enclosing, source)
226226

@@ -252,13 +252,15 @@ object Summarization {
252252
}
253253

254254
def resolveThis(cls: ClassSymbol, pot: Potential, cur: ClassSymbol, source: Tree)(implicit env: Env): Summary =
255+
trace("resolve " + cls.show + ", pot = " + pot.show + ", cur = " + cur.show, init, s => Summary.show(s.asInstanceOf[Summary])) {
255256
if (cls.is(Flags.Package)) (Potentials.empty, Effects.empty)
256257
else if (cls == cur) (pot.toPots, Effects.empty)
257258
else if (pot.size > 2) (Potentials.empty, Promote(pot)(source).toEffs)
258259
else {
259260
val pot2 = Outer(pot, cur)(pot.source)
260-
resolveThis(cls, pot2, cur.enclosingClass.asClass, source)
261+
resolveThis(cls, pot2, cur.lexicallyEnclosingClass.asClass, source)
261262
}
263+
}
262264

263265
/** Summarize secondary constructors or class body */
264266
def analyzeConstructor(ctor: Symbol)(implicit env: Env): Summary =

0 commit comments

Comments
 (0)