Skip to content

Commit 27cd90f

Browse files
committed
Fixes handling of op-assignments for polymorphic apply/update.
See t3252 for a test case.
1 parent 57b616c commit 27cd90f

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,14 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
759759
Ident(defn.ScalaRuntimeModule.requiredMethod(name).termRef).appliedToArgs(args)
760760
}
761761

762+
/** An extractor that pulls out type arguments */
763+
object MaybePoly {
764+
def unapply(tree: Tree): Option[(Tree, List[Tree])] = tree match {
765+
case TypeApply(tree, targs) => Some(tree, targs)
766+
case _ => Some(tree, Nil)
767+
}
768+
}
769+
762770
/** A traverser that passes the enlcosing class or method as an argumenr
763771
* to the traverse method.
764772
*/

src/dotty/tools/dotc/typer/EtaExpansion.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ object EtaExpansion {
3434
* lhs += expr
3535
*/
3636
def liftAssigned(defs: mutable.ListBuffer[Tree], tree: Tree)(implicit ctx: Context): Tree = tree match {
37-
case Apply(fn @ Select(pre, name), args) =>
38-
cpy.Apply(tree)(cpy.Select(fn)(lift(defs, pre), name), liftArgs(defs, fn.tpe, args))
37+
case Apply(MaybePoly(fn @ Select(pre, name), targs), args) =>
38+
cpy.Apply(tree)(
39+
cpy.Select(fn)(
40+
lift(defs, pre), name).appliedToTypeTrees(targs),
41+
liftArgs(defs, fn.tpe, args))
3942
case Select(pre, name) =>
4043
cpy.Select(tree)(lift(defs, pre), name)
4144
case _ =>

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,13 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
400400
tree.lhs match {
401401
case lhs @ Apply(fn, args) =>
402402
typed(cpy.Apply(lhs)(untpd.Select(fn, nme.update), args :+ tree.rhs), pt)
403-
case untpd.TypedSplice(Apply(Select(fn, app), args)) if app == nme.apply =>
404-
typed(cpy.Apply(fn)(
405-
untpd.Select(untpd.TypedSplice(fn), nme.update),
406-
(args map untpd.TypedSplice) :+ tree.rhs), pt)
403+
case untpd.TypedSplice(Apply(MaybePoly(Select(fn, app), targs), args)) if app == nme.apply =>
404+
val rawUpdate: untpd.Tree = untpd.Select(untpd.TypedSplice(fn), nme.update)
405+
val wrappedUpdate =
406+
if (targs.isEmpty) rawUpdate
407+
else untpd.TypeApply(rawUpdate, targs map untpd.TypedSplice)
408+
val appliedUpdate = cpy.Apply(fn)(wrappedUpdate, (args map untpd.TypedSplice) :+ tree.rhs)
409+
typed(appliedUpdate, pt)
407410
case lhs =>
408411
val lhsCore = typedUnadapted(lhs)
409412
def lhs1 = typed(untpd.TypedSplice(lhsCore))
File renamed without changes.

0 commit comments

Comments
 (0)