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