File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed
compiler/src/dotty/tools/dotc/core Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -1194,10 +1194,10 @@ object Types {
1194
1194
* then the top-level union isn't widened. This is needed so that type inference can infer nullable types.
1195
1195
*/
1196
1196
def widenUnion (implicit ctx : Context ): Type = widen match {
1197
- case OrType (tp1, tp2) =>
1198
- if (ctx.explicitNulls && isNullableUnion) {
1197
+ case tp @ OrType (tp1, tp2) =>
1198
+ if (ctx.explicitNulls && tp. isNullableUnion) {
1199
1199
// Don't widen `T|Null`, since otherwise we wouldn't be able to infer nullable unions.
1200
- val OrType (leftTpe, nullTpe) = normNullableUnion
1200
+ val OrType (leftTpe, nullTpe) = tp. normNullableUnion
1201
1201
OrType (leftTpe.widenUnion, nullTpe)
1202
1202
} else {
1203
1203
ctx.typeComparer.lub(tp1.widenUnion, tp2.widenUnion, canConstrain = true ) match {
Original file line number Diff line number Diff line change
1
+
2
+ // Test that we correctly handle nullable unions when widening
3
+ // (we don't widen them).
4
+ class Test {
5
+ def foo (): Unit = {
6
+ val x : String | Null = ???
7
+ val y = x // this used to crash the compiler
8
+ }
9
+ }
You can’t perform that action at this time.
0 commit comments