Skip to content

Commit a2465b1

Browse files
OlivierBlanvillainDarkDimius
authored andcommitted
Refactor the temporary tpd fix
1 parent dec2766 commit a2465b1

File tree

1 file changed

+17
-31
lines changed

1 file changed

+17
-31
lines changed

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

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -473,33 +473,24 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
473473
}
474474

475475
override def Apply(tree: Tree)(fun: Tree, args: List[Tree])(implicit ctx: Context): Apply = {
476-
if (ctx.settings.optimise.value) {
477-
val untyped = untpd.cpy.Apply(tree)(fun, args)
478-
val typed = ta.assignType(untyped, fun, args)
479-
if (untyped.ne(tree))
480-
typed
481-
else
482-
tree.asInstanceOf[Apply]
483-
} else {
484-
ta.assignType(untpd.cpy.Apply(tree)(fun, args), fun, args)
485-
}
476+
val untyped = untpd.cpy.Apply(tree)(fun, args)
477+
if (untyped.ne(tree) || !ctx.settings.optimise.value)
478+
ta.assignType(untyped, fun, args)
479+
else
480+
tree.asInstanceOf[Apply]
486481
}
482+
487483
// Note: Reassigning the original type if `fun` and `args` have the same types as before
488484
// does not work here: The computed type depends on the widened function type, not
489485
// the function type itself. A treetransform may keep the function type the
490486
// same but its widened type might change.
491487

492488
override def TypeApply(tree: Tree)(fun: Tree, args: List[Tree])(implicit ctx: Context): TypeApply = {
493-
if (ctx.settings.optimise.value) {
494-
val untyped = untpd.cpy.TypeApply(tree)(fun, args)
495-
val typed = ta.assignType(untyped, fun, args)
496-
if (untyped.ne(tree))
497-
typed
498-
else
499-
tree.asInstanceOf[TypeApply]
500-
} else {
501-
ta.assignType(untpd.cpy.TypeApply(tree)(fun, args), fun, args)
502-
}
489+
val untyped = untpd.cpy.TypeApply(tree)(fun, args)
490+
if (untyped.ne(tree) || !ctx.settings.optimise.value)
491+
ta.assignType(untyped, fun, args)
492+
else
493+
tree.asInstanceOf[TypeApply]
503494
}
504495
// Same remark as for Apply
505496

@@ -535,16 +526,12 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
535526
}
536527

537528
override def Closure(tree: Tree)(env: List[Tree], meth: Tree, tpt: Tree)(implicit ctx: Context): Closure = {
538-
if (ctx.settings.optimise.value) {
539-
val untyped = untpd.cpy.Closure(tree)(env, meth, tpt)
540-
val typed = ta.assignType(untyped, meth, tpt)
541-
if (untyped.ne(tree))
542-
typed
543-
else
544-
tree.asInstanceOf[Closure]
545-
} else {
546-
ta.assignType(untpd.cpy.Closure(tree)(env, meth, tpt), meth, tpt)
547-
}
529+
val untyped = untpd.cpy.Closure(tree)(env, meth, tpt)
530+
val typed = ta.assignType(untyped, meth, tpt)
531+
if (untyped.ne(tree) || !ctx.settings.optimise.value)
532+
typed
533+
else
534+
tree.asInstanceOf[Closure]
548535
}
549536
// Same remark as for Apply
550537

@@ -980,4 +967,3 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
980967
if (file != null && file.exists) new SourceFile(file, Codec(encoding)) else NoSource
981968
}
982969
}
983-

0 commit comments

Comments
 (0)