-
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
Disallow private opaque type aliases #14666
Conversation
Co-authored-by: Jamie Thompson <[email protected]>
A private opaque type alias is equivalent to a private type alias
Opaque types whose usage is limited to the scope where they are defined (and where they are not seen as opaque) indeed seem to make no sense so they can be disabled. But I think it makes sense to allow scoped private access like this trait Foo:
class Bar:
private[Foo] opaque type Baz = Int
def foo: Bar#Baz Even when the current changes from this PR are applied the code snippet above crashes the compiler. Instead this should compile successfully. |
Sorry for butting in, why do private opaque types make no sense? Suppose I have a private method |
@adampauls The idea is that |
It does remove the compiler's ability to type check for you right? |
@adampauls That's true whether |
The hidden test is unreliable after typer, since we cannot guarantee that the current owner is accurate.
We also needed to fix a problem when merging denotations with hidden symbols The hidden test is unreliable after typer, since we cannot guarantee that the |
In fact, to fix #14660, only the last commit is necessary. Forbidding |
Thanks, sorry I did not carefully RTFM. I had thought from a first read that the scope of transparency was the companion object of the type alias. If I want to make the equivalent of a private object CheckedFooScope {
opaque type CheckedFoo = Foo
object CheckedFoo {
def apply(foo: Foo): CheckedFoo = foo
}
}
import CheckedFooScope.CheckedFoo |
@@ -51,6 +51,8 @@ object o: | |||
def id(x: o.T): o.T = x | |||
``` | |||
|
|||
Opaque type aliases cannot be `private` and cannot be overridden in subclasses. |
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 think we should point out that private[OuterScope]
is allowed however.
Another thing that might not be very clear here is that one can define an abstract type and then override (or implement) it with an opaque type
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 think that could be elsewhere, maybe in a tutorial. The doc here is a spec and conciseness is good. If we say however it can be private[X] the we'd have to go to all other places where we say private
and include or exclude private X
.
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.
If it's consistent across the docs that private[Scope]
is not private
then it's OK
Fixes #14660