-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Partial application of bounded type operator fails bounds check #9695
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
Comments
I do not think the error is related to type Bar[+A] = [B <: A] =>> Int Fails with the following error: -- Error: /Users/kmetiuk/Projects/scala3/playground/iwip/Bad.scala:1:10 --------
1 |type Bar[+A] = [B <: A] =>> Int
| ^^
|covariant type parameter A occurs in contravariant position in [B <: A] =>> Int
1 error found Also in the neg tests, there is a code that specifically tests for such a variance failure: The variance of The compiler thinks The above code is executed from: (line 59) Theoretically you can insert there: case t@TypeBounds(_, _) =>
x Before |
I might be missing something, but I never claimed that there's anything wrong with It could be that currying type operators with variance annotations like this should be forbidden, but I'm not sure that's the case. If it's not, then the two should behave the same. |
I see now that my original code snippet uses object Test {
type Foo[+A, +B <: A] = B // uncurried -> OK
type Bar[+A] = [B <: A] =>> B // curried -> fails
} where it should now be visually obvious that |
There seems to be some inconsistency between curried and uncurried type operators. This means that partially applying certain operators fails.
Minimized code
Output
Expectation
I'd expect the two versions to behave the same. The definition of
Foo
is correct, IMO. The typeA
does not appear in a contravariant position inside the definition/body ofFoo
— in fact it doesn't appear at all. It does appear in a bound in the signature ofFoo
but that shouldn't matter (the signature is not part of the definition). That means that the error inBar
is probably a false negative. I'm not sure why the bounds of type lambdas are considered in variance checking.This may or may not be related to #6320 and #6499.
Tagging @Blaisorblade and @smarter since the example resulted from a discussion we had about variance checking.
The text was updated successfully, but these errors were encountered: