-
Notifications
You must be signed in to change notification settings - Fork 21
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
Type inference involving getClass
on private trait doesn't work
#12974
Comments
I would like to take a look at this. |
That shouldn't be allowed to compile for a more important reason: the private type |
@sjrd I tried to simplify it as much as I can but in my real scenario, |
Yes please — let's make sure we're all on the same page on the exact code required. |
Done! |
minimized even further, it's: trait Bug {
private trait Style
private def foo(style: Style): Set[Class[? <: Style]] =
Set(style.getClass)
} @lrytz It seems puzzling to me that private-ness would even affect typing here. Curious if you have (or anyone has) a hunch what mechanism might be involved here? |
There's always more magic to discover.
The bound is made up here: https://github.com/scala/scala/blob/v2.13.13/src/compiler/scala/tools/nsc/typechecker/Typers.scala#L645-L646. I guess that can be fixed for private classes.
|
When Seth quotes that line of doc on the ticket, he says, "In Java 6...". It's interesting to see what tools our grandparents used to solve problems. The special handling was introduced for 2.10. |
getClass
on private trait doesn't work
Reproduction steps
On scala 2.13.13 (scala 3 infers correctly)
gives the following error:
but if I remove the
private[style]
annotation onStyle
, or if I caststyle.getClass
asClass[Style]
, it compiles and works correctly.Problem
I expect the compiler to infer the type correctly whether it is a private or non private trait. In scala 3, the compiler infers it correctly.
The text was updated successfully, but these errors were encountered: