File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed
compiler/src/dotty/tools/dotc/printing Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -649,10 +649,29 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
649649 val tp = tp1.tryNormalize
650650 if (tp != NoType ) tp else tp1
651651 }
652+ val tp3 =
653+ if (homogenizedView && tree.isInstanceOf [If | Match | Annotated | Block | CaseDef ]) {
654+ // Types of non-leaf trees are not pickled but reconstructed when
655+ // unpickled using the TypeAssigner. Sometimes, this requires choosing
656+ // arbitrarily between two =:= types (e.g., when typing an `if`, where
657+ // one branch is typed with a type alias and the other with a
658+ // dealiased version of the same type) and we cannot guarantee that
659+ // the same choice was made by the original Typer (e.g., because the
660+ // original choice involved type variables). So we need to get rid of
661+ // any alias in these types to make -Ytest-pickler work (the list of
662+ // types in the isInstanceOf check above is conservative and might
663+ // need to be expanded).
664+ val dealiasMap = new TypeMap {
665+ def apply (tp : Type ) = mapOver(tp.dealias)
666+ }
667+ dealiasMap(tp2)
668+ }
669+ else tp2
670+
652671 if (! suppressTypes)
653- txt = (" <" ~ txt ~ " :" ~ toText(tp2 ) ~ " >" ).close
672+ txt = (" <" ~ txt ~ " :" ~ toText(tp3 ) ~ " >" ).close
654673 else if (tree.isType && ! homogenizedView)
655- txt = toText(tp2 )
674+ txt = toText(tp3 )
656675 }
657676 if (! suppressPositions) {
658677 if (printPos) {
You can’t perform that action at this time.
0 commit comments