forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
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 scala#15646 from Linyxus/fix-if-union-b
Fix GADT casting when typing if expressions
- Loading branch information
Showing
5 changed files
with
110 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
trait Expr[T] | ||
case class IntExpr() extends Expr[Int] | ||
|
||
def flag: Boolean = ??? | ||
|
||
def foo[T](ev: Expr[T]): Int | T = ev match | ||
case IntExpr() => | ||
if flag then | ||
val i: T = ??? | ||
i | ||
else | ||
(??? : Int) |
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,13 @@ | ||
enum SUB[-A, +B]: | ||
case Refl[S]() extends SUB[S, S] | ||
|
||
trait R { | ||
type Data | ||
} | ||
trait L extends R | ||
|
||
def f(x: L): x.Data = ??? | ||
|
||
def g[T <: R](x: T, ev: T SUB L): x.Data = ev match | ||
case SUB.Refl() => | ||
f(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,15 @@ | ||
trait T1 | ||
trait T2 extends T1 | ||
|
||
trait Expr[T] { val data: T = ??? } | ||
case class Tag2() extends Expr[T2] | ||
|
||
def flag: Boolean = ??? | ||
|
||
def foo[T](e: Expr[T]): T1 = e match { | ||
case Tag2() => | ||
flag match | ||
case true => new T2 {} | ||
case false => e.data | ||
} | ||
|
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 @@ | ||
trait T1 | ||
trait T2 extends T1 | ||
|
||
trait Expr[T] { val data: T = ??? } | ||
case class Tag2() extends Expr[T2] | ||
|
||
def flag: Boolean = ??? | ||
|
||
def foo[T](e: Expr[T]): T1 = e match { | ||
case Tag2() => | ||
if flag then | ||
new T2 {} | ||
else | ||
e.data | ||
} | ||
|