-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #17467: Limit isNullable widening to stable TermRefs.
The Scala language specification has a peculiar clause about the nullness of singleton types of the form `path.type`. It says that `Null <:< path.type` if the *underlying* type `U` of `path` is nullable itself. The previous implementation of that rule was overly broad, as it indiscrimately widened all types. This resulted in problematic subtyping relationships like `Null <:< "foo"`. We do not widen anymore. Instead, we specifically handle `TermRef`s of stable members, which are how dotc represents singleton types. We also have a rule for `Null <:< null`, which is necessary for pattern matching exhaustivity to keep working in the presence of nulls.
- Loading branch information
Showing
3 changed files
with
44 additions
and
2 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,31 @@ | ||
object Test: | ||
def test(): Unit = | ||
val a1: String = "foo" | ||
val a2: a1.type = null // OK | ||
|
||
val b1: "foo" = null // error | ||
|
||
val c1: "foo" = "foo" | ||
val c2: c1.type = null // error | ||
|
||
type MyNullable = String | ||
val d1: MyNullable = "foo" | ||
val d2: d1.type = null // OK | ||
|
||
type MyNonNullable = Int | ||
val e1: MyNonNullable = 5 | ||
val e2: e1.type = null // error | ||
|
||
summon[Null <:< "foo"] // error | ||
|
||
val f1: Mod.type = null // error | ||
|
||
var g1: AnyRef = "foo" | ||
val g2: g1.type = null // error // error | ||
end test | ||
|
||
object Mod | ||
|
||
class Bar: | ||
def me: this.type = null // error | ||
end Test |
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