Skip to content

Commit 29a1771

Browse files
committed
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.
1 parent 5ba8ea3 commit 29a1771

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,13 +567,14 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
567567
def typedAssign(tree: untpd.Assign, pt: Type)(implicit ctx: Context) = track("typedAssign") {
568568
tree.lhs match {
569569
case lhs @ Apply(fn, args) =>
570-
typed(cpy.Apply(lhs)(untpd.Select(fn, nme.update), args :+ tree.rhs), pt)
570+
typed(untpd.Apply(untpd.Select(fn, nme.update), args :+ tree.rhs), pt)
571571
case untpd.TypedSplice(Apply(MaybePoly(Select(fn, app), targs), args)) if app == nme.apply =>
572572
val rawUpdate: untpd.Tree = untpd.Select(untpd.TypedSplice(fn), nme.update)
573573
val wrappedUpdate =
574574
if (targs.isEmpty) rawUpdate
575575
else untpd.TypeApply(rawUpdate, targs map (untpd.TypedSplice(_)))
576-
val appliedUpdate = cpy.Apply(fn)(wrappedUpdate, (args map (untpd.TypedSplice(_))) :+ tree.rhs)
576+
val appliedUpdate =
577+
untpd.Apply(wrappedUpdate, (args map (untpd.TypedSplice(_))) :+ tree.rhs)
577578
typed(appliedUpdate, pt)
578579
case lhs =>
579580
val lhsCore = typedUnadapted(lhs, AssignProto)
@@ -604,7 +605,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
604605
val setterType = ensureAccessible(setterTypeRaw, isSuperSelection(lhsCore), tree.pos)
605606
val lhs2 = healNonvariant(
606607
untpd.rename(lhsCore, setterName).withType(setterType), WildcardType)
607-
typedUnadapted(cpy.Apply(tree)(untpd.TypedSplice(lhs2), tree.rhs :: Nil))
608+
typedUnadapted(untpd.Apply(untpd.TypedSplice(lhs2), tree.rhs :: Nil))
608609
case _ =>
609610
reassignmentToVal
610611
}

0 commit comments

Comments
 (0)