Skip to content

Commit c093792

Browse files
committed
Map proxy references in constructors to parameters
Proxy references in constructors can't be left as fields because they can happen before the supercall.
1 parent 9bf44f8 commit c093792

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/dotty/tools/dotc/transform/LambdaLift.scala

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,24 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisTransform
391391
val freeParamDefs = ownProxies.map(proxy =>
392392
transformFollowingDeep(ValDef(proxy.asTerm).withPos(tree.pos)).asInstanceOf[ValDef])
393393
def proxyInit(field: Symbol, param: Symbol) =
394-
transformFollowingDeep(ref(field).becomes(ref(param)))
394+
transformFollowingDeep(memberRef(field).becomes(ref(param)))
395+
396+
/** Map references to proxy fields `this.proxy` to procy parameers */
397+
def mapProxies = new TreeMap {
398+
override def transform(tree: Tree)(implicit ctx: Context) = tree match {
399+
case Select(This(_), _) if proxies contains tree.symbol =>
400+
ref(tree.symbol.subst(proxies, ownProxies))
401+
case _ =>
402+
super.transform(tree)
403+
}
404+
}
405+
406+
/** Initialize proxy fields from proxy parameters and map `rhs` from fields to parameters */
395407
def copyParams(rhs: Tree) = {
396408
ctx.log(i"copy params ${proxies.map(_.showLocated)}%, %, own = ${ownProxies.map(_.showLocated)}%, %")
397-
seq((proxies, ownProxies).zipped.map(proxyInit), rhs)
409+
seq((proxies, ownProxies).zipped.map(proxyInit), mapProxies.transform(rhs))
398410
}
411+
399412
tree match {
400413
case tree: DefDef =>
401414
cpy.DefDef(tree)(
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)