Skip to content

Commit 09bcded

Browse files
Merge pull request #4071 from dotty-staging/fix-#4060
Fix #4060 by marking ghost symbols as unstable
2 parents 3cc41cd + 6d17f08 commit 09bcded

File tree

7 files changed

+57
-30
lines changed

7 files changed

+57
-30
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ object SymDenotations {
600600

601601
/** Is this a denotation of a stable term (or an arbitrary type)? */
602602
final def isStable(implicit ctx: Context) =
603-
isType || is(Stable) || !(is(UnstableValue) || info.isInstanceOf[ExprType])
603+
isType || !is(Erased) && (is(Stable) || !(is(UnstableValue) || info.isInstanceOf[ExprType]))
604604

605605
/** Is this a "real" method? A real method is a method which is:
606606
* - not an accessor

tests/neg/erased-24.scala

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Could become a run test if we had totality checking for erased arguments
2+
3+
object Test {
4+
5+
def main(args: Array[String]): Unit = {
6+
println(fun(new Bar))
7+
}
8+
9+
def fun(erased foo: Foo): foo.X = { // error
10+
null.asInstanceOf[foo.X] // error
11+
}
12+
13+
def fun2(erased foo: Foo)(erased bar: foo.B): bar.X = { // error // error
14+
null.asInstanceOf[bar.X] // error
15+
}
16+
}
17+
18+
class Foo {
19+
type X
20+
type B <: Bar
21+
}
22+
23+
class Bar extends Foo {
24+
type X = String
25+
}

tests/pos/erased-pathdep-1.scala renamed to tests/neg/erased-pathdep-1.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
// Could become a neg test if we had totality checking for erased arguments
2+
13
object Test {
24

35
fun1(new Bar)
46
fun2(new Bar)
57
fun3(new Bar)
68

7-
def fun1[F >: Bar <: Foo](erased f: F): f.X = null.asInstanceOf[f.X]
8-
def fun2[F >: Bar <: Foo](erased f: F)(erased bar: f.B): f.B = null.asInstanceOf[f.B]
9-
def fun3[F >: Bar <: Foo](erased f: F)(erased b: f.B): b.X = null.asInstanceOf[b.X]
9+
def fun1[F >: Bar <: Foo](erased f: F): f.X = null.asInstanceOf[f.X] // error // error
10+
def fun2[F >: Bar <: Foo](erased f: F)(erased bar: f.B): f.B = null.asInstanceOf[f.B] // error // error // error
11+
def fun3[F >: Bar <: Foo](erased f: F)(erased b: f.B): b.X = null.asInstanceOf[b.X] // error // error // error
1012
}
1113

1214
class Foo {

tests/pos/erased-pathdep-2.scala renamed to tests/neg/erased-pathdep-2.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
// Could become a neg test if we had totality checking for erased arguments
2+
13
object Test {
24

35
type F >: Bar <: Foo
46

57
class A(erased val f: F) {
6-
type F1 <: f.X
7-
type F2[Z <: f.X]
8+
type F1 <: f.X // error
9+
type F2[Z <: f.X] // error
810
}
911

1012
}

tests/neg/i4060.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class X { type R }
2+
class T(erased val a: X)(val value: a.R) // error
3+
4+
object App {
5+
def coerce[U, V](u: U): V = {
6+
trait X { type R >: U }
7+
trait Y { type R = V }
8+
9+
class T[A <: X](erased val a: A)(val value: a.R) // error
10+
11+
object O { lazy val x : Y & X = ??? } // warning
12+
13+
val a = new T[Y & X](O.x)(u)
14+
a.value
15+
}
16+
17+
def main(args: Array[String]): Unit = {
18+
val x: Int = coerce[String, Int]("a")
19+
println(x + 1)
20+
21+
}
22+
}

tests/run/erased-24.check

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/run/erased-24.scala

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)