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
- Loading branch information
1 parent
20a576f
commit dbbc0b5
Showing
10 changed files
with
121 additions
and
15 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,16 @@ | ||
package test | ||
|
||
class Thing { | ||
def info: Info[this.type] = InfoRepository.getInfo(this) | ||
def info2: Info[this.type] = { | ||
def self: this.type = this | ||
InfoRepository.getInfo(self) // error: not a legal path | ||
} | ||
} | ||
|
||
trait Info[T] | ||
case class InfoImpl[T](thing: T) extends Info[T] | ||
|
||
object InfoRepository { | ||
def getInfo(t: Thing): Info[t.type] = InfoImpl(t) | ||
} |
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 | ||
} |
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