-
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.
Under explicit nulls, remove the rule
Null <:< x.type
.
The specified rule that `Null <:< x.type` when the underlying type `U` of `x` is nullable is dubious to begin with. Under explicit nulls, it becomes decidedly out of place. We now disable that rule under `-Yexplicit-nulls`.
- Loading branch information
Showing
3 changed files
with
48 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,31 @@ | ||
-- [E007] Type Mismatch Error: tests/explicit-nulls/neg/i17467.scala:4:22 ---------------------------------------------- | ||
4 | val a2: a1.type = null // error | ||
| ^^^^ | ||
| Found: Null | ||
| Required: (a1 : String) | ||
| Note that implicit conversions were not tried because the result of an implicit conversion | ||
| must be more specific than (a1 : String) | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E007] Type Mismatch Error: tests/explicit-nulls/neg/i17467.scala:7:22 ---------------------------------------------- | ||
7 | val b2: b1.type = null // error | ||
| ^^^^ | ||
| Found: Null | ||
| Required: (b1 : String | Null) | ||
| Note that implicit conversions were not tried because the result of an implicit conversion | ||
| must be more specific than (b1 : String | Null) | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E172] Type Error: tests/explicit-nulls/neg/i17467.scala:8:28 ------------------------------------------------------- | ||
8 | summon[Null <:< b1.type] // error | ||
| ^ | ||
| Cannot prove that Null <:< (b1 : String | Null). | ||
-- [E007] Type Mismatch Error: tests/explicit-nulls/neg/i17467.scala:14:22 --------------------------------------------- | ||
14 | val c2: c1.type = null // error | ||
| ^^^^ | ||
| Found: Null | ||
| Required: (c1 : Null) | ||
| Note that implicit conversions were not tried because the result of an implicit conversion | ||
| must be more specific than (c1 : Null) | ||
| | ||
| longer explanation available when compiling with `-explain` |
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,16 @@ | ||
object Test: | ||
def test(): Unit = | ||
val a1: String = "foo" | ||
val a2: a1.type = null // error | ||
|
||
val b1: String | Null = "foo" | ||
val b2: b1.type = null // error | ||
summon[Null <:< b1.type] // error | ||
|
||
/* The following would be sound, but it would require a specific subtyping | ||
* rule (and implementation code) for debatable value. So it is an error. | ||
*/ | ||
val c1: Null = null | ||
val c2: c1.type = null // error | ||
end test | ||
end Test |