-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Make toplevel opaque types transparent to the whole file #21530
Closed
Closed
Changes from all commits
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 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,7 @@ | ||
import OpaqueBug.* | ||
def g(n: Counter): Counter = n | ||
object OpaqueBug: | ||
opaque type Counter = Int | ||
val initial: Counter = 42 | ||
def f(n: Int): Int = g(n) + initial | ||
@main def run = println(f(21)) |
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,6 @@ | ||
opaque type Counter = Int | ||
def g(n: Counter): Counter = n | ||
object OpaqueBug: | ||
val initial: Counter = 42 // was error: Found: (42 : Int) | ||
def f(n: Int): Int = g(n) + initial // was error: Found: (n : Int) Required: Counter | ||
@main def run = println(f(21)) |
Oops, something went wrong.
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.
Isn't that going to create a
C$.this
reference outside ofC$
? If yes, I don't think that's supposed to be possible/valid.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.
The reference wasn't outside when the user wrote it. The compiler moved it so it's nested in a package object, but to the user the call site isn't from "outside".
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 understand, but still ... from an elaborated, TASTy-level point of view, this is invalid. A
C.this
reference has no meaning outside ofC
. This is worse than being "not accessible" because ofprotected
or even "not visible" because ofprivate
; here it does not even exist.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'd argue that C.this, where C is a singleton module is just an alternative to C.type. Which, btw, is what
widenInferred
does as a final cleanup.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.
It represents the same set of values at run-time, sure, but it's not valid everywhere
C.type
is valid.AFAICT,
widentInferred
turnspre.C$
intopre.C
; notC$.this
intopre.C
nor the converse.