-
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
Strange behaviour related to type test of path-dependent types and divergence from Scala 2 #20354
Comments
What does Scla 2 give for the |
The problem that IntOpt with the member commented out does not get an outer pointer, and we cannot change that. We could restrict the type system to prevent the match as Scala 2 does. But it could be easily circumvented by widening: (SecondParser.OptMinSuccess: Any) match {
case _: FirstParser.IntOpt => println("true")
case _ => println("false")
} So I think it's best to verify that we have an outer pointer and if that's not the case we issue a warning that the full type cannot be tested at run time. |
It returns
I was surprised to find my understanding of outers in Scala incorrect. Is this behavior specified somewhere? Or it's just an optimization that has become de facto standard? /cc: @sjrd |
It would be quite inefficient if every inner trait needed an outer pointer. So it gets one only if the body references an outer member. I don't know whether that's specced. |
This reverts one part of scala#20261. When we fail with both an ambiguity on one implicit argument and another error on another we prefer the other error. I added a comment why this is needed. Fixes scala#20354
Compiler version
3.5.0-RC1-bin-20240506-1cdf99f-NIGHTLY
Minimized code
Output
If we comment out the following line in
trait IntOpt
:We get
In contrast, Scala 2 reports a compilation error for the pattern match in both versions:
Expectation
false false
trait
should not change type test resultThe text was updated successfully, but these errors were encountered: