-
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.
A tweak to type improvement (#21312)
When we replace Nothing by a fresh type variable, we should not accidentally instantiate that type variable to Any in case it is still undetermined. We achieve this by giving the type variable a slightly disguised version of Nothing which makes the compiler believe it has a lower bound. Fixes #21275
- Loading branch information
Showing
2 changed files
with
19 additions
and
1 deletion.
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,10 @@ | ||
class Box[+O]: | ||
def ++[O2 >: O](other: Box[O2]): Box[O2] = ??? | ||
object Box: | ||
val empty: Box[Nothing] = ??? | ||
|
||
def test[T]: Box[T] = | ||
List(Box.empty, Box.empty) | ||
// .reduceOption[Box[T]](_ ++ _) // works | ||
.reduceOption(_ ++ _) // fails | ||
.getOrElse(Box.empty) |