forked from scala/scala3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix scala#4031: Check arguments of dependent methods for realizability
The first attempt required changing z1720.scala; but that became unnecessary after aligning isRealizable with isStable. A TermRef is stable if its underlying type is stable. Realizability should behave the same way.
- Loading branch information
1 parent
72ea704
commit 61629e3
Showing
8 changed files
with
97 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
object App { | ||
trait A { type L >: Any} | ||
def upcast(a: A, x: Any): a.L = x | ||
lazy val p: A { type L <: Nothing } = p | ||
val q = new A { type L = Any } | ||
def coerce2(x: Any): Int = upcast(p, x): p.L // error: not a legal path | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
object App { | ||
trait A { type L >: Any} | ||
def upcast(a: A, x: Any): a.L = x | ||
lazy val p: A { type L <: Nothing } = p | ||
val q = new A { type L = Any } | ||
def coerce(x: Any): Int = upcast(p, x) // error: not a legal path | ||
|
||
def compare(x: A, y: x.L) = assert(x == y) | ||
def compare2(x: A)(y: x.type) = assert(x == y) | ||
|
||
|
||
def main(args: Array[String]): Unit = { | ||
println(coerce("Uh oh!")) | ||
compare(p, p) // error: not a legal path | ||
compare2(p)(p) // error: not a legal path | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class C { type T } | ||
|
||
class Test { | ||
|
||
type D <: C | ||
|
||
lazy val a: C = ??? | ||
final lazy val b: C = ??? | ||
val c: D = ??? | ||
final lazy val d: D = ??? | ||
|
||
val x1: a.T = ??? // error: not a legal path, since a is lazy & non-final | ||
val x2: b.T = ??? // OK, b is lazy but concrete | ||
val x3: c.T = ??? // OK, c is abstract but strict | ||
val x4: d.T = ??? // error: not a legal path since d is abstract and lazy | ||
|
||
val y1: Singleton = a | ||
val y2: Singleton = a | ||
val y3: Singleton = a | ||
val y4: Singleton = a | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
object App { | ||
trait A { type L >: Any} | ||
def upcast(a: A, x: Any): a.L = x | ||
lazy val p: A { type L <: Nothing } = p | ||
val q = new A { type L = Any } | ||
def coerce1(x: Any): Any = upcast(q, x) // ok | ||
def coerce3(x: Any): Any = upcast(p, x) // ok, since dependent result type is not needed | ||
} |