-
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
Weird opaque types behaviour #15050
Comments
Example 1 looks like a bug, Example 2 is expected behavior (though I agree it's confusing): top-level definitions are wrapped into a top-level object generated by the compiler (you can verify this using |
So in the |
Top-level definitions are visible in the whole file, but opaque types only behave as type alias in the scope where they're defined, which for top-level definition is a compile-generated object, so you can refer to the opaque type in OpaqueBug but it will behave like an abstract type. |
I worded my conclusion wrong; by visible I meant that the type it aliases, in this case, that |
The first example also won't work. The way things are set up is that inside val OpaqueBug: OpaqueBug$ = new OpaqueBug$()
class OpaqueBug$ { this: OpaqueBug$ { type Counter = Int } => ... } So, |
Compiler version
I'be tested this on scala 3.0.0 and scala 3.1.2
Example 1
And the compiler complains with:
I'd would expect this code to compile because when we do the
+
the compiler should know thanCounter
is simply anInt
.Example 2
If I move the opaque definition outside of the object:
Then the compiler complains with
And I'd expect this code to compile without problems.
So, is this a bug or a feature (and it's me that I do not understand how opaque types should work)?
The text was updated successfully, but these errors were encountered: