-
Notifications
You must be signed in to change notification settings - Fork 21
Generic signature for wildcards changed in 2.13.7 #12488
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 almost felt like Object is right, seeing as TT is covariant and declaration-side variance isn't representable in Java. But it's Which lead me to compare what it looks like with another upper bound: class Foo
trait T[+X <: Foo] { def x: X }
class C {
type TT[+X <: Foo] = T[X]
def it(): TT[_] = new TT[Foo] { def x = new Foo }
} And that also emits That is because I assumed
Confused... 🤯 |
Bisected to scala/scala#9693 |
Uncurry's |
Yes I already suspected as much but didn't have time to look at it yet. It's unfortunate that Scala doesn't dealias when computing the erasure (and bytecode signature). It leads to this kind of problems all the time 😬 |
can you elaborate? uncurry should remove type aliases, and it's before erasure. there are no type aliases in the bytecode involved here, not in the method signatures, nor in their generic signatures. |
Oh sorry I think I confused an old PR of mine but it was specific to higher-kinded types: scala/scala#8720 |
That's right
|
Given |
In I already tried to add those bounds to wildcards but I think it breaks down for F-bounded type parameters and for inferred existential types. Perhaps worth another try 🤔 - but if that subtype relationship were true, it doesn't fix the OP does it? |
If I understand the spec correctly, |
Scala 3 only has wildcards, no existentials, so it handles this differently it seems: scala> trait T[+X <: String]
scala> val t: T[String] = (null: T[_])
val t: T[String] = null |
The equivalent question in Scala 3 is if |
Also from that part of the spec:
|
I looked a bit at Java;
javac 11 tells me public class A {
public static class T<X> { }
public static void main(String[] args) {
T<? extends Object> t1a = null;
T<Object> t1b = null;
T t1c = null;
T<? super Object> t1d = null;
t1a = t1b;
t1a = t1c; // warning: [unchecked] unchecked conversion
t1a = t1d;
// t1b = t1a; // error: T<CAP#1> cannot be converted to T<Object>
t1b = t1c; // warning: [unchecked] unchecked conversion
t1b = t1d;
t1c = t1a;
t1c = t1b;
t1c = t1d;
// t1d = t1a; // error: T<CAP#1> cannot be converted to T<? super Object>
t1d = t1b;
t1d = t1c; // warning: [unchecked] unchecked conversion
}
} So this would cause a problem if a generic signature goes from Here are the rules (I didn't study them): https://docs.oracle.com/javase/specs/jls/se17/html/jls-4.html#jls-4.5.1 |
No, I was just exploring with another upper bound, but then found an issue in my motivation. I'm somewhat convinced that the fact it compiles in Scala 3 means it's wrong in Scala 2. Anyways, thanks for the answers. |
So I think where things break down is that the spec states "for a covariant |
Maybe by booking it under "Java interop is best-effort"? |
The attempt at scala/scala#9812 looks promising but not entirely trivial. I think we don't need to block 2.13.8 over this issue because
|
Bookmarking #11480 |
The regression shows only when using the type alias. Discovered by @octonato and MiMa on Akka.
Not sure if that has any impact on Java clients. The following Java code works, no matter if the Scala code was compiled with 2.12.6 or 2.12.7:
The text was updated successfully, but these errors were encountered: