Skip to content

Commit 25c9f96

Browse files
committed
Add tests for scala#4060 and small change in i11896
For i11896, we now no longer allow an erased val to be of a top-level type declaration X (since it is not a concrete type, per realizability rules). `class X` is used instead. Another test, `top-level-type`, was added to check this behaviour.
1 parent 0c8964b commit 25c9f96

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// See https://github.com/lampepfl/dotty/issues/4060#issuecomment-445808377
2+
3+
object App {
4+
trait A { type L >: Any}
5+
//def upcast(a: A, x: Any): a.L = x
6+
def upcast(erased a: A)(x: Any): a.L = x
7+
//lazy val p: A { type L <: Nothing } = p
8+
erased val p: A { type L <: Nothing } = p // error
9+
def coerce(x: Any): Int = upcast(p)(x)
10+
11+
def main(args: Array[String]): Unit = {
12+
println(coerce("Uh oh!"))
13+
}
14+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import scala.language.experimental.erasedDefinitions
2+
3+
type X
4+
erased def x : X = compiletime.erasedValue // error

tests/pos-custom-args/erased/i11896.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import scala.language.experimental.erasedDefinitions
22

3-
type X
3+
class X
44
erased def x: X = compiletime.erasedValue
55

66
def foo(using erased X): Unit = ()

0 commit comments

Comments
 (0)