-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #5521: prefix not checked in realizability check #5522
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
Merged
Changes from 1 commit
Commits
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,12 @@ | ||
class Hello { | ||
class Foo { | ||
class Bar | ||
final lazy val s: Bar = ??? | ||
} | ||
|
||
lazy val foo: Foo = ??? | ||
|
||
val x: foo.s.type = ??? // error: `foo` must be final since it's a lazy val | ||
val x2: foo.s.type = ??? // error: `foo` must be final since it's a lazy val | ||
} | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at this time ago in #4036, I should look more closely, and I'm in a rush, but here are some initial comments.
I agree this is a bug and this change should give the correct behavior; but this change risks being pretty computationally expensive (possible fix below). This can duplicate recursive calls, and that risks causing exponential slowdowns. Triggering it might require a chain of final lazy vals or be impossible, but it's more robust to not duplicate calls.
If
isLateInitialized(sym)
, this callsrealizability(tp.prefix)
again, and that can be too expensive. Caching only affects symbols, but we don't cacherealizability
on whole types;tp
could not even be aTermRef
and fall throughboundsRealizability(tp).andAlso(memberRealizability(tp))
.I asked dottybot for a performance test. But maybe one could just reorganize the logic.
Looking at #4036 (which is where I "studied" this), I propose to add to your change the following:
because in this branch we can certainly mark the symbol as stable (that PR also achieves this goal, though in a hackier way). If that works, this PR can go in with that fix.
Optional requests
Here's a couple of bonus requests one could fix here as well — if they are non-trivial, feel free to defer them. I should probably do these changes myself and PR them, I'm in a rush right now.
On performance: https://github.com/lampepfl/dotty/pull/4036/files#diff-0535d82f8f57a2204d6452bae575efc9 might be a useful test here (if it doesn't cause a stack overflow).
On error reporting, I think one could cherry-pick from #4036 the following: