Skip to content

Commit 7b9f0cb

Browse files
committed
Deskolemize after fully defining type
The order was the opposite before. That led to skolem types escaping in the constraint and then being installed in the inferred type of a val or def.
1 parent 01447df commit 7b9f0cb

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,13 @@ class PlainPrinter(_ctx: Context) extends Printer {
459459
if (idx >= 0) selfRecName(idx + 1)
460460
else "{...}.this" // TODO move underlying type to an addendum, e.g. ... z3 ... where z3: ...
461461
case tp: SkolemType =>
462-
if (homogenizedView) toText(tp.info)
463-
else if (ctx.settings.XprintTypes.value) "<" ~ toText(tp.repr) ~ ":" ~ toText(tp.info) ~ ">"
464-
else toText(tp.repr)
462+
def reprStr = toText(tp.repr) ~ hashStr(tp)
463+
if homogenizedView then
464+
toText(tp.info)
465+
else if ctx.settings.XprintTypes.value then
466+
"<" ~ reprStr ~ ":" ~ toText(tp.info) ~ ">"
467+
else
468+
reprStr
465469
}
466470
}
467471

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2245,8 +2245,9 @@ class Namer { typer: Typer =>
22452245
// it would be erased to BoxedUnit.
22462246
def dealiasIfUnit(tp: Type) = if (tp.isRef(defn.UnitClass)) defn.UnitType else tp
22472247

2248-
def cookedRhsType = dealiasIfUnit(rhsType).deskolemized
2248+
def cookedRhsType = dealiasIfUnit(rhsType)
22492249
def lhsType = fullyDefinedType(cookedRhsType, "right-hand side", mdef.srcPos)
2250+
.deskolemized
22502251
//if (sym.name.toString == "y") println(i"rhs = $rhsType, cooked = $cookedRhsType")
22512252
if (inherited.exists)
22522253
if sym.isInlineVal || isTracked then lhsType else inherited

tests/pending/pos/i23489.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import scala.language.experimental.modularity
2+
3+
class Box1[T <: Singleton](val x: T)
4+
class Box2[T : Singleton](x: => T)
5+
def id(x: Int): x.type = x
6+
def readInt(): Int = ???
7+
8+
def Test = ()
9+
val x = Box1(id(readInt()))
10+
11+
val _: Box1[? <: Int] = x
12+
13+
val y = Box2(id(readInt())) // error

0 commit comments

Comments
 (0)