From 29a1771e11a38490217a678bb7b2a05c2bbe9e37 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Fri, 14 Jul 2017 20:33:08 +0200 Subject: [PATCH] Fix positions in assignments TreeCopier#finalize will set the position of the new tree to the old tree, which is not what we want here since the desugared tree position should contain more than the position of the parsed assignment lhs. Moreover, the desugared tree will never be identical to the parsed lhs so there is no reason to use a TreeCopier at all. --- compiler/src/dotty/tools/dotc/typer/Typer.scala | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 289ec44c0a3c..b2a23e680bfd 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -567,13 +567,14 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit def typedAssign(tree: untpd.Assign, pt: Type)(implicit ctx: Context) = track("typedAssign") { tree.lhs match { case lhs @ Apply(fn, args) => - typed(cpy.Apply(lhs)(untpd.Select(fn, nme.update), args :+ tree.rhs), pt) + typed(untpd.Apply(untpd.Select(fn, nme.update), args :+ tree.rhs), pt) case untpd.TypedSplice(Apply(MaybePoly(Select(fn, app), targs), args)) if app == nme.apply => val rawUpdate: untpd.Tree = untpd.Select(untpd.TypedSplice(fn), nme.update) val wrappedUpdate = if (targs.isEmpty) rawUpdate else untpd.TypeApply(rawUpdate, targs map (untpd.TypedSplice(_))) - val appliedUpdate = cpy.Apply(fn)(wrappedUpdate, (args map (untpd.TypedSplice(_))) :+ tree.rhs) + val appliedUpdate = + untpd.Apply(wrappedUpdate, (args map (untpd.TypedSplice(_))) :+ tree.rhs) typed(appliedUpdate, pt) case lhs => val lhsCore = typedUnadapted(lhs, AssignProto) @@ -604,7 +605,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit val setterType = ensureAccessible(setterTypeRaw, isSuperSelection(lhsCore), tree.pos) val lhs2 = healNonvariant( untpd.rename(lhsCore, setterName).withType(setterType), WildcardType) - typedUnadapted(cpy.Apply(tree)(untpd.TypedSplice(lhs2), tree.rhs :: Nil)) + typedUnadapted(untpd.Apply(untpd.TypedSplice(lhs2), tree.rhs :: Nil)) case _ => reassignmentToVal }