Skip to content

Commit 16fa957

Browse files
committed
Make compile-time operations on stable arguments stable
1 parent 7c8667e commit 16fa957

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ object Types {
175175
// see: tests/explicit-nulls/pos/flow-stable.scala.disabled
176176
tp.tp1.isStable && (realizability(tp.tp2) eq Realizable) ||
177177
tp.tp2.isStable && (realizability(tp.tp1) eq Realizable)
178+
case AppliedType(tycon: TypeRef, args) if defn.isCompiletimeAppliedType(tycon.symbol) && args.forall(_.isStable) => true
178179
case _ => false
179180
}
180181

tests/neg/singleton-ops-int.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,24 @@ object Test {
116116

117117
val t83: ToDouble[1] = 1.0
118118
val t84: ToDouble[2] = 2 // error
119+
120+
// Singletons are dereferenced
121+
val t85: Int = 5
122+
val t86: t85.type = t85
123+
summon[t85.type + t85.type =:= t86.type + t86.type]
124+
125+
// Singletons are dereferenced recursively
126+
val t87: t86.type = t87
127+
summon[t85.type + t85.type =:= t87.type + t87.type]
128+
129+
// Skolems of compile-time types are dereferenced:
130+
// (?1 : (Test.x : Int) * (Test.x : Int)) --> (Test.x : Int) * (Test.x : Int)
131+
def mult(x: Int, y: Int): x.type * y.type = (x * y).asInstanceOf
132+
val t88: t85.type * t85.type * t85.type = mult(mult(t85, t85), t85)
133+
134+
// Compile-time operations with singleton arguments are singletons
135+
summon[t85.type + t86.type <:< Singleton]
136+
137+
// Compile-time operations with non-singleton arguments are not singletons
138+
summon[t85.type + Int <:< Singleton] // error
119139
}

0 commit comments

Comments
 (0)