Skip to content

Commit daf736c

Browse files
committed
Replace aliases to Unit by Unit
Do this in the inferred (result-)type of ValDefs and DefDefs. Without this fix, TreeTraverser#traverseChildren in Trees.scala gets a result type of BoxedUnit (but only when co-compiled from source, not when unpickled).
1 parent 09eddd0 commit daf736c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,13 +824,21 @@ class Namer { typer: Typer =>
824824
// println(s"final inherited for $sym: ${inherited.toString}") !!!
825825
// println(s"owner = ${sym.owner}, decls = ${sym.owner.info.decls.show}")
826826
def isInline = sym.is(Final, butNot = Method)
827+
828+
// Widen rhs type and approximate `|' but keep ConstantTypes if
829+
// definition is inline (i.e. final in Scala2).
827830
def widenRhs(tp: Type): Type = tp.widenTermRefExpr match {
828831
case tp: ConstantType if isInline => tp
829832
case _ => tp.widen.approximateUnion
830833
}
834+
835+
// Replace aliases to Unit by Unit itself. If we leave the alias in
836+
// it would be erased to BoxedUnit.
837+
def dealiasIfUnit(tp: Type) = if (tp.isRef(defn.UnitClass)) defn.UnitType else tp
838+
831839
val rhsCtx = ctx.addMode(Mode.InferringReturnType)
832840
def rhsType = typedAheadExpr(mdef.rhs, inherited orElse rhsProto)(rhsCtx).tpe
833-
def cookedRhsType = ctx.deskolemize(widenRhs(rhsType))
841+
def cookedRhsType = ctx.deskolemize(dealiasIfUnit(widenRhs(rhsType)))
834842
lazy val lhsType = fullyDefinedType(cookedRhsType, "right-hand side", mdef.pos)
835843
//if (sym.name.toString == "y") println(i"rhs = $rhsType, cooked = $cookedRhsType")
836844
if (inherited.exists)

0 commit comments

Comments
 (0)