-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Teach SpaceEngine that generic tuples are irrefutable
- Loading branch information
Showing
6 changed files
with
65 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
object Foo: | ||
def unapply[T <: Tuple](tup: T): String *: String *: T = | ||
"a" *: "b" *: tup | ||
|
||
// like {pos,neg}/i15991, but with an abstract tuple tail | ||
class Test: | ||
val tup2: String *: String *: EmptyTuple = ("c", "d") | ||
|
||
def test3 = | ||
val Foo(x, y, z) = tup2 // error: Wrong number of argument patterns for Foo; expected: (String, String, String, String) | ||
x + y + z | ||
|
||
def test3a = | ||
val x1x = tup2 match | ||
case Foo(x, y, z) => // error: Wrong number of argument patterns for Foo; expected: (String, String, String, String) | ||
(x, y, z) | ||
val x = x1x._1 | ||
val y = x1x._2 | ||
val z = x1x._3 | ||
x + y + z |
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 Foo: | ||
def unapply(x: Any): String *: String *: EmptyTuple = ("a", "b") | ||
|
||
class Test: | ||
def test = | ||
val Foo(x, y, z) = 1 // error: Wrong number of argument patterns for Foo; expected: (String, String) | ||
x + y + z |
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,20 @@ | ||
object Foo: | ||
def unapply[T <: Tuple](tup: T): String *: String *: T = | ||
"a" *: "b" *: tup | ||
|
||
// like {pos,neg}/i15991, but with an abstract tuple tail | ||
class Test: | ||
val tup2: String *: String *: EmptyTuple = ("c", "d") | ||
|
||
def test2 = | ||
val Foo(x, y, _, _) = tup2 | ||
x + y | ||
|
||
// like test2, but as the desugaring of what PatternDef's become | ||
def test2b = | ||
val x1x = tup2 match | ||
case Foo(x, y, _, _) => | ||
(x, y) | ||
val x = x1x._1 | ||
val y = x1x._2 | ||
x + y |
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,9 @@ | ||
class Foo | ||
|
||
object Foo: | ||
// def unapply(f: Foo): (Int, Int) = ??? // does not raise a warning | ||
def unapply(f: Foo): Int *: Int *: EmptyTuple = ??? | ||
|
||
@main def example = | ||
val Foo(x, y) = new Foo | ||
println(x) |
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 Foo: | ||
def unapply(x: Any): String *: String *: EmptyTuple = | ||
("a", "b") | ||
|
||
class Test: | ||
def test = | ||
val Foo(x, y) = 1 | ||
x + y |