@@ -90,6 +90,9 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisTransform
90
90
free.getOrElse(sym, Nil ).toList.map(pm)
91
91
}
92
92
93
+ /** Set `liftedOwner(sym)` to `owner` if `owner` is more deeply nested
94
+ * than the previous value of `liftedowner(sym)`.
95
+ */
93
96
def narrowLiftedOwner (sym : Symbol , owner : Symbol )(implicit ctx : Context ) = {
94
97
if (sym.owner.isTerm &&
95
98
owner.isProperlyContainedIn(liftedOwner(sym)) &&
@@ -100,12 +103,22 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisTransform
100
103
}
101
104
}
102
105
103
- /** Mark symbol `sym` as being free in `enclosure`, unless `sym`
104
- * is defined in `enclosure` or there is a class between `enclosure`s owner
105
- * and the owner of `sym`. Also, update lifted owner of `enclosure` so
106
+ /** Mark symbol `sym` as being free in `enclosure`, unless `sym` is defined
107
+ * in `enclosure` or there is an intermediate class properly containing `enclosure`
108
+ * in which `sym` is also free . Also, update `liftedOwner` of `enclosure` so
106
109
* that `enclosure` can access `sym`, or its proxy in an intermediate class.
110
+ * This means:
111
+ *
112
+ * 1. If there is an intermediate class in which `sym` is free, `enclosure`
113
+ * must be contained in that class (in order to access the `sym proxy stored
114
+ * in the class).
115
+ *
116
+ * 2. If there is no intermediate class, `enclosure` must be contained
117
+ * in the class enclosing `sym`.
118
+ *
107
119
* Return the closest enclosing intermediate class between `enclosure` and
108
- * the owner of sym, or NoSymbol is none exists.
120
+ * the owner of sym, or NoSymbol if none exists.
121
+ *
109
122
* pre: sym.owner.isTerm, (enclosure.isMethod || enclosure.isClass)
110
123
*
111
124
* The idea of `markFree` is illustrated with an example:
@@ -139,7 +152,9 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisTransform
139
152
ctx.debuglog(i " $enclosure != ${sym.enclosure}" )
140
153
val intermediate =
141
154
if (enclosure.is(PackageClass )) enclosure
142
- else markFree(sym, enclosure.skipConstructor.enclosure)
155
+ else markFree(sym, enclosure.skipConstructor.enclosure)
156
+ // `enclosure` might be a constructor, in which case we want the enclosure
157
+ // of the enclosing class, so skipConstructor is needed here.
143
158
if (intermediate.exists) {
144
159
narrowLiftedOwner(enclosure, intermediate)
145
160
intermediate
0 commit comments