@@ -92,9 +92,10 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisTransform
92
92
}
93
93
94
94
def narrowLiftedOwner (sym : Symbol , owner : Symbol )(implicit ctx : Context ) = {
95
- ctx.log(i " narrow lifted $sym to $owner" )
96
- if (sym.owner.skipConstructor.isTerm &&
97
- owner.isProperlyContainedIn(liftedOwner(sym))) {
95
+ if (sym.owner.isTerm &&
96
+ owner.isProperlyContainedIn(liftedOwner(sym)) &&
97
+ owner != sym) {
98
+ ctx.log(i " narrow lifted $sym to $owner" )
98
99
changedLiftedOwner = true
99
100
liftedOwner(sym) = owner
100
101
}
@@ -133,9 +134,9 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisTransform
133
134
private def markFree (sym : Symbol , enclosure : Symbol )(implicit ctx : Context ): Boolean = try {
134
135
if (! enclosure.exists) throw new NoPath
135
136
ctx.log(i " mark free: ${sym.showLocated} with owner ${sym.maybeOwner} marked free in $enclosure" )
137
+ narrowLiftedOwner(enclosure, sym.enclosingClass)
136
138
(enclosure == sym.enclosure) || {
137
139
ctx.debuglog(i " $enclosure != ${sym.enclosure}" )
138
- narrowLiftedOwner(enclosure, sym.enclosingClass)
139
140
if (enclosure.is(PackageClass ) ||
140
141
! markFree(sym, enclosure.skipConstructor.enclosure)) false
141
142
else {
@@ -165,6 +166,13 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisTransform
165
166
def traverse (enclMeth : Symbol , tree : Tree ) = try { // debug
166
167
val enclosure = enclMeth.skipConstructor
167
168
val sym = tree.symbol
169
+ def narrowTo (thisClass : ClassSymbol ) = {
170
+ val enclClass = enclosure.enclosingClass
171
+ if (! thisClass.isStaticOwner)
172
+ narrowLiftedOwner(enclosure,
173
+ if (enclClass.isContainedIn(thisClass)) thisClass
174
+ else enclClass) // unknown this reference, play it safe and assume the narrowest possible owner
175
+ }
168
176
tree match {
169
177
case tree : Ident =>
170
178
if (sym.maybeOwner.isTerm) {
@@ -173,17 +181,13 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisTransform
173
181
i " attempt to refer to label $sym from nested $enclosure" )
174
182
else if (sym is Method ) markCalled(sym, enclosure)
175
183
else if (sym.isTerm) markFree(sym, enclosure)
176
- }
184
+ } else if (sym.maybeOwner.isClass)
185
+ narrowTo(sym.owner.asClass)
177
186
case tree : Select =>
178
187
if (sym.isConstructor && sym.owner.owner.isTerm)
179
188
markCalled(sym, enclosure)
180
189
case tree : This =>
181
- val thisClass = tree.symbol.asClass
182
- val enclClass = enclosure.enclosingClass
183
- if (! thisClass.isStaticOwner && thisClass != enclClass)
184
- narrowLiftedOwner(enclosure,
185
- if (enclClass.isContainedIn(thisClass)) thisClass
186
- else enclClass) // unknown this reference, play it safe and assume the narrowest possible owner
190
+ narrowTo(tree.symbol.asClass)
187
191
case tree : DefDef =>
188
192
if (sym.owner.isTerm && ! sym.is(Label )) liftedOwner(sym) = sym.topLevelClass.owner
189
193
else if (sym.isPrimaryConstructor && sym.owner.owner.isTerm) symSet(called, sym) += sym.owner
0 commit comments