-
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.
Merge pull request #14590 from dwijnand/patmat-fix-generic-tuple-casting
- Loading branch information
Showing
6 changed files
with
50 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// scalac: -Werror | ||
class Test: | ||
type Foo = Option[String] | Option[Int] | ||
|
||
def test(foo: Foo) = | ||
val (_, foo2: Foo) = // was: the type test for Test.this.Foo cannot be checked at runtime | ||
foo match | ||
case Some(s: String) => ((), s) | ||
case _ => ((), 0) | ||
foo2 |
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,10 @@ | ||
object Test: | ||
def test(cond: Boolean) = | ||
val tup: (String, Unit) | (Int, Unit) = if cond then ("", ()) else (1, ()) | ||
tup match | ||
case (s: String, _) => s | ||
case _ => "n/a" | ||
|
||
def main(args: Array[String]): Unit = | ||
test(true) // works | ||
test(false) // was: ClassCastException: class scala.None$ cannot be cast to class scala.Some |
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 Test: | ||
opaque type Tup = (Int, String) | ||
|
||
def test(tup: Tup) = | ||
val (n, s) = tup | ||
assert(n == 1 && s == "") | ||
|
||
def main(args: Array[String]): Unit = test((1, "")) |
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 @@ | ||
def test(foo: String): Unit = { | ||
// Does not crash if the type is written explicitly as: Option[(Option[Int], String)] | ||
val bar = { | ||
if (foo.isEmpty) Some((Some(1), "")) | ||
else Some((None, "")) | ||
} | ||
|
||
bar.foreach { | ||
case (Some(_), "") => | ||
case _ => | ||
} | ||
} | ||
|
||
@main def Test() = | ||
test("") // works | ||
test("a") |