forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instantiate more type variables to hard unions
Fixes scala#14770
- Loading branch information
Showing
9 changed files
with
128 additions
and
38 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
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
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 @@ | ||
type UndefOr[A] = A | Unit | ||
|
||
extension [A](maybe: UndefOr[A]) | ||
def foreach(f: A => Unit): Unit = | ||
maybe match | ||
case () => () | ||
case a: A => f(a) | ||
|
||
trait Foo | ||
trait Bar | ||
|
||
object Baz: | ||
var booBap: Foo | Bar = _ | ||
|
||
def z: UndefOr[Foo | Bar] = ??? | ||
|
||
@main | ||
def main = | ||
z.foreach(x => Baz.booBap = x) | ||
|
||
def test[A](v: A | Unit): A | Unit = v | ||
val x1 = test(5: Int | Unit) | ||
val x2 = test(5: String | Int | Unit) | ||
val _: Int | Unit = x1 | ||
val _: String | Int | Unit = x2 |