type inference regression related to JDK-8157149
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Tue Oct 18 10:27:34 UTC 2016
You are right - JDK-8157149 introduced a regression in the treatment of
propagation of poly expressions to outer contexts. This is caused by the
fact that the propagation logic doesn't take this bullet from 18.5.2
into account:
"Otherwise, if R θ is an inference variable α, and one of the following
is true:
T is a reference type, but is not a wildcard-parameterized type,
and either i) B2 contains a bound of one of the forms α = S or S <: α,
where S is a wildcard-parameterized type, or ii) B2 contains two bounds
of the forms S1 <: α and S2 <: α, where S1 and S2 have supertypes that
are two different parameterizations of the same generic class or interface.
T is a parameterization of a generic class or interface, G, and B2
contains a bound of one of the forms α = S or S <: α, where there exists
no type of the form G<...> that is a supertype of S, but the raw type
|G<...>| is a supertype of S.
* T is a primitive type, and one of the primitive wrapper classes
mentioned in §5.1.7 is an instantiation, upper bound, or lower bound for
α in B2.*
then α is resolved in B2, and where the capture of the resulting
instantiation of α is U, the constraint formula ‹U → T› is reduced and
incorporated with B2. "
And as a result, javac tries to propagate the nested constraint f(i) ->
long into the outer context, which is incorrect, because the type of
f(i) needs to be eagerly instantiated.
Filed https://bugs.openjdk.java.net/browse/JDK-8168134
Thanks again
Maurizio
On 17/10/16 18:36, Maurizio Cimadamore wrote:
>
> I'll take a look - thanks for the report.
>
> Maurizio
>
> On 17/10/16 17:14, Liam Miller-Cushon wrote:
>> javac started rejecting the following program between 9-ea+119 and
>> 9-ea+120. The culprit appears to be JDK-8157149 [1][2]. Was this
>> intentional?
>>
>> Thanks,
>>
>> [1] https://bugs.openjdk.java.net/browse/JDK-8157149
>> <https://bugs.openjdk.java.net/browse/JDK-8157149>
>> [2] http://hg.openjdk.java.net/jdk9/dev/langtools/rev/a8b7c9938b74
>> <http://hg.openjdk.java.net/jdk9/dev/langtools/rev/a8b7c9938b74>
>>
>> === Test.java
>> abstract class Test {
>> interface W<A> {}
>> abstract <B> B f(W<B> e);
>> abstract <C> C g(C b, long i);
>>
>> void h(W<Long> i) {
>> g("", f(i));
>> }
>> }
>> ===
>>
>> $ javac Test.java
>> ...
>> error: method g in class Test cannot be applied to given types;
>> g("", f(i));
>> ^
>> required: C,long
>> found: String,Long
>> reason: cannot infer type-variable(s) C,B
>> (argument mismatch; B cannot be converted to long)
>> where C,B are type-variables:
>> C extends Object declared in method <C>g(C,long)
>> B extends Object declared in method <B>f(W<B>)
>> 1 error
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20161018/af07eb2d/attachment-0001.html>
More information about the compiler-dev
mailing list