Skip to content

Commit a32b5ca

Browse files
committed
Fix pickling tests failing with smarter tpd.
This also seems to be a reason why Ycheck:front fails. typeAssigner is REMOVING partial evaluation that typer did when you copy a tree. It means that types would be different if you test pickling. Temporary(permanent) solution: don't print constant types in pickling.
1 parent 4f39455 commit a32b5ca

File tree

3 files changed

+28
-33
lines changed

3 files changed

+28
-33
lines changed

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

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -473,33 +473,27 @@ 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+
val typed = ta.assignType(untyped, fun, args)
478+
if (untyped.ne(tree))
479+
typed
480+
else
481+
tree.asInstanceOf[Apply]
486482
}
487-
// Note: Reassigning the original type if `fun` and `args` have the same types as before
483+
484+
// Note: Reassigning the original type if `fun` and `args` have the same types as before
488485
// does not work here: The computed type depends on the widened function type, not
489486
// the function type itself. A treetransform may keep the function type the
490487
// same but its widened type might change.
491488

492489
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-
}
490+
val untyped = untpd.cpy.TypeApply(tree)(fun, args)
491+
val typed = ta.assignType(untyped, fun, args)
492+
if (untyped.ne(tree))
493+
typed
494+
else
495+
tree.asInstanceOf[TypeApply]
496+
503497
}
504498
// Same remark as for Apply
505499

@@ -535,16 +529,12 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
535529
}
536530

537531
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-
}
532+
val untyped = untpd.cpy.Closure(tree)(env, meth, tpt)
533+
val typed = ta.assignType(untyped, meth, tpt)
534+
if (untyped.ne(tree))
535+
typed
536+
else
537+
tree.asInstanceOf[Closure]
548538
}
549539
// Same remark as for Apply
550540

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ class PlainPrinter(_ctx: Context) extends Printer {
5353
case AndType(tp1, tp2) =>
5454
homogenize(tp1) & homogenize(tp2)
5555
case OrType(tp1, tp2) =>
56-
homogenize(tp1) | homogenize(tp2)
56+
if (tp1.classSymbol.id > tp2.classSymbol.id)
57+
homogenize(tp1) | homogenize(tp2)
58+
else homogenize(tp2) | homogenize(tp1)
5759
case tp: SkolemType =>
5860
homogenize(tp.info)
5961
case tp: LazyRef =>

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
124124
toTextTuple(args.init)
125125
("implicit " provided isImplicit) ~ argStr ~ " => " ~ argText(args.last)
126126
}
127-
homogenize(tp) match {
127+
val htp = homogenize(tp)
128+
htp match {
129+
case x: ConstantType if homogenizedView =>
130+
return toText(x.widen)
128131
case AppliedType(tycon, args) =>
129132
val cls = tycon.typeSymbol
130133
if (tycon.isRepeatedParam) return toTextLocal(args.head) ~ "*"

0 commit comments

Comments
 (0)