Skip to content

Commit d4cbbe5

Browse files
committed
deskolemize the type of ValDef
1 parent a781883 commit d4cbbe5

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,6 @@ object Types {
12081208
if tp.isOverloaded then tp else tp.underlying.widen
12091209
case tp: SingletonType => tp.underlying.widen
12101210
case tp: ExprType => tp.resultType.widen
1211-
case tp: AndType => tp.derivedAndType(tp.tp1.widen, tp.tp2.widen)
12121211
case tp =>
12131212
val tp1 = tp.stripped
12141213
if tp1 eq tp then tp
@@ -1390,6 +1389,17 @@ object Types {
13901389
/** Like `dealiasKeepAnnots`, but keeps only refining annotations */
13911390
final def dealiasKeepRefiningAnnots(using Context): Type = dealias1(keepIfRefining)
13921391

1392+
/** Approximate this type with a type that does not contain skolem types. */
1393+
final def deskolemized(using Context): Type =
1394+
val deskolemizer = new ApproximatingTypeMap {
1395+
def apply(tp: Type) = /*trace(i"deskolemize($tp) at $variance", show = true)*/
1396+
tp match {
1397+
case tp: SkolemType => range(defn.NothingType, atVariance(1)(apply(tp.info)))
1398+
case _ => mapOver(tp)
1399+
}
1400+
}
1401+
deskolemizer(this)
1402+
13931403
/** The result of normalization using `tryNormalize`, or the type itself if
13941404
* tryNormlize yields NoType
13951405
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ abstract class Lifter {
4848
else {
4949
val name = UniqueName.fresh(prefix)
5050
// don't instantiate here, as the type params could be further constrained, see tests/pos/pickleinf.scala
51-
var liftedType = expr.tpe.widen
51+
var liftedType = expr.tpe.widen.deskolemized
5252
if (liftedFlags.is(Method)) liftedType = ExprType(liftedType)
5353
val lifted = newSymbol(ctx.owner, name, liftedFlags | Synthetic, liftedType, coord = spanCoord(expr.span))
5454
defs += liftedDef(lifted, expr)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1713,7 +1713,7 @@ class Namer { typer: Typer =>
17131713
}
17141714
}
17151715

1716-
def cookedRhsType = deskolemize(dealiasIfUnit(rhsType))
1716+
def cookedRhsType = dealiasIfUnit(rhsType).deskolemized
17171717
def lhsType = fullyDefinedType(cookedRhsType, "right-hand side", mdef.span)
17181718
//if (sym.name.toString == "y") println(i"rhs = $rhsType, cooked = $cookedRhsType")
17191719
if (inherited.exists)

tests/pos/i13197.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ extension [T](x: T | String) inline def forceString: x.type & String =
66
trait Bar:
77
def b: String | Int
88

9-
class Foo(a: String = "", b: Any)
9+
class Foo(a: String = "", b: String)
1010

1111
object Foo:
1212
def foo(bar: Bar) = Foo(b = bar.b.forceString)

0 commit comments

Comments
 (0)