-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #17467: Limit isNullable widening to stable TermRefs; remove under explicit nulls. #17470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+158
−2
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 | ||
dwijnand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end Test |
This file contains hidden or 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,64 @@ | ||
-- [E007] Type Mismatch Error: tests/neg/i17467.scala:6:20 ------------------------------------------------------------- | ||
6 | val b1: "foo" = null // error | ||
| ^^^^ | ||
| Found: Null | ||
| Required: ("foo" : String) | ||
| Note that implicit conversions were not tried because the result of an implicit conversion | ||
| must be more specific than ("foo" : String) | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E007] Type Mismatch Error: tests/neg/i17467.scala:9:22 ------------------------------------------------------------- | ||
9 | val c2: c1.type = null // error | ||
| ^^^^ | ||
| Found: Null | ||
| Required: (c1 : ("foo" : String)) | ||
| Note that implicit conversions were not tried because the result of an implicit conversion | ||
| must be more specific than (c1 : ("foo" : String)) | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E007] Type Mismatch Error: tests/neg/i17467.scala:17:22 ------------------------------------------------------------ | ||
17 | val e2: e1.type = null // error | ||
| ^^^^ | ||
| Found: Null | ||
| Required: (e1 : MyNonNullable) | ||
| Note that implicit conversions were not tried because the result of an implicit conversion | ||
| must be more specific than (e1 : MyNonNullable) | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E172] Type Error: tests/neg/i17467.scala:19:26 --------------------------------------------------------------------- | ||
19 | summon[Null <:< "foo"] // error | ||
| ^ | ||
| Cannot prove that Null <:< ("foo" : String). | ||
-- [E007] Type Mismatch Error: tests/neg/i17467.scala:21:23 ------------------------------------------------------------ | ||
21 | val f1: Mod.type = null // error | ||
| ^^^^ | ||
| Found: Null | ||
| Required: Test.Mod.type | ||
| Note that implicit conversions were not tried because the result of an implicit conversion | ||
| must be more specific than Test.Mod.type | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E083] Type Error: tests/neg/i17467.scala:24:12 --------------------------------------------------------------------- | ||
24 | val g2: g1.type = null // error // error | ||
| ^^^^^^^ | ||
| (g1 : AnyRef) is not a valid singleton type, since it is not an immutable path | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E007] Type Mismatch Error: tests/neg/i17467.scala:24:22 ------------------------------------------------------------ | ||
24 | val g2: g1.type = null // error // error | ||
| ^^^^ | ||
| Found: Null | ||
| Required: (g1 : AnyRef) | ||
| Note that implicit conversions were not tried because the result of an implicit conversion | ||
| must be more specific than (g1 : AnyRef) | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E007] Type Mismatch Error: tests/neg/i17467.scala:33:24 ------------------------------------------------------------ | ||
33 | def me: this.type = null // error | ||
| ^^^^ | ||
| Found: Null | ||
| Required: (Bar.this : Test.Bar) | ||
| Note that implicit conversions were not tried because the result of an implicit conversion | ||
| must be more specific than (Bar.this : Test.Bar) | ||
| | ||
| longer explanation available when compiling with `-explain` |
This file contains hidden or 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,34 @@ | ||
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" | ||
dwijnand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
val g2: g1.type = null // error // error | ||
|
||
val h1: Null = null | ||
val h2: h1.type = null | ||
end test | ||
|
||
object Mod | ||
|
||
class Bar: | ||
def me: this.type = null // error | ||
end Test |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.