@@ -33,7 +33,7 @@ object HoistSuperArgs {
33
33
*
34
34
* An argument is complex if it contains a method or template definition, a this or a new,
35
35
* or it contains an identifier which needs a `this` prefix to be accessed. This is the case
36
- * if the identifer neither a global reference nor a reference to a parameter of the enclosing class.
36
+ * if the identifier has neither a global reference nor a reference to a parameter of the enclosing class.
37
37
* @see needsHoist for an implementation.
38
38
*
39
39
* A hoisted argument definition gets the parameters of the class it is hoisted from
@@ -116,21 +116,26 @@ class HoistSuperArgs extends MiniPhase with IdentityDenotTransformer { thisPhase
116
116
case _ => false
117
117
}
118
118
119
+ /** Only rewire types that are owned by the current Hoister and is an param or accessor */
120
+ def needsRewire (tp : Type ) = tp match {
121
+ case ntp : NamedType =>
122
+ (ntp.symbol.owner == cls || ntp.symbol.owner == constr) && ntp.symbol.isParamOrAccessor
123
+ case _ => false
124
+ }
125
+
119
126
// begin hoistSuperArg
120
127
arg match {
121
128
case Apply (fn, arg1 :: Nil ) if fn.symbol == defn.cbnArg =>
122
129
cpy.Apply (arg)(fn, hoistSuperArg(arg1, cdef) :: Nil )
123
- case _ if ( arg.existsSubTree(needsHoist) ) =>
130
+ case _ if arg.existsSubTree(needsHoist) =>
124
131
val superMeth = newSuperArgMethod(arg.tpe)
125
132
val superArgDef = polyDefDef(superMeth, trefs => vrefss => {
126
133
val paramSyms = trefs.map(_.typeSymbol) ::: vrefss.flatten.map(_.symbol)
127
134
val tmap = new TreeTypeMap (
128
135
typeMap = new TypeMap {
129
136
lazy val origToParam = origParams.zip(paramSyms).toMap
130
137
def apply (tp : Type ) = tp match {
131
- case tp : NamedType
132
- if (tp.symbol.owner == cls || tp.symbol.owner == constr) &&
133
- tp.symbol.isParamOrAccessor =>
138
+ case tp : NamedType if needsRewire(tp) =>
134
139
origToParam.get(tp.symbol) match {
135
140
case Some (mappedSym) => if (tp.symbol.isType) mappedSym.typeRef else mappedSym.termRef
136
141
case None => mapOver(tp)
@@ -140,7 +145,7 @@ class HoistSuperArgs extends MiniPhase with IdentityDenotTransformer { thisPhase
140
145
}
141
146
},
142
147
treeMap = {
143
- case tree : RefTree if paramSyms.contains (tree.symbol ) =>
148
+ case tree : RefTree if needsRewire (tree.tpe ) =>
144
149
cpy.Ident (tree)(tree.name).withType(tree.tpe)
145
150
case tree =>
146
151
tree
0 commit comments