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.
Don't widen components of a hard union
- Loading branch information
Showing
3 changed files
with
69 additions
and
7 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,37 @@ | ||
enum A: | ||
case B | ||
case C | ||
case D | ||
|
||
object A: | ||
type B_type = B.type | ||
type C_type = C.type | ||
type D_type = D.type | ||
|
||
type Matcher[T] = T match | ||
case A.C.type | A.D.type => Int | ||
case A.B.type => Float | ||
|
||
class Test: | ||
def fn[U <: A](u: U)(value: Matcher[U]): Matcher[U] = value | ||
|
||
def t1: Unit = | ||
val a: A.C_type | A.D_type = A.C | ||
val x = fn(a)(5) | ||
|
||
def t2: Unit = | ||
val a: A.C.type | A.D.type = A.C | ||
val x = fn(a)(5) // was: | ||
// ^ | ||
// Found: (5 : Int) | ||
// Required: Matcher[A] | ||
// | ||
// Note: a match type could not be fully reduced: | ||
// | ||
// trying to reduce Matcher[A] | ||
// failed since selector A | ||
// does not match case (A.C : A) | (A.D : A) => Int | ||
// and cannot be shown to be disjoint from it either. | ||
// Therefore, reduction cannot advance to the remaining case | ||
// | ||
// case (A.B : A) => Float |
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,25 @@ | ||
sealed abstract class A | ||
|
||
object A: | ||
case object B extends A | ||
case object C extends A | ||
case object D extends A | ||
|
||
type B_type = B.type | ||
type C_type = C.type | ||
type D_type = D.type | ||
|
||
type Matcher[T] = T match | ||
case A.C.type | A.D.type => Int | ||
case A.B.type => Float | ||
|
||
class Test: | ||
def fn[U <: A](u: U)(value: Matcher[U]): Matcher[U] = value | ||
|
||
def t1: Unit = | ||
val a: A.C_type | A.D_type = A.C | ||
val x = fn(a)(5) | ||
|
||
def t2: Unit = | ||
val a: A.C.type | A.D.type = A.C | ||
val x = fn(a)(5) |