intersection type compatibility
Stephan Herrmann
stephan.herrmann at berlin.de
Sat Dec 7 07:29:29 PST 2013
Comments inline ...
On 12/06/2013 08:01 PM, Dan Smith wrote:
> On Dec 3, 2013, at 8:26 AM, Stephan Herrmann <stephan.herrmann at berlin.de> wrote:
>
>> Consider this program:
>>
>> import java.util.ArrayList;
>> import java.util.List;
>>
>> public class Compile {
>>
>> public <T, Exp extends List<T>> Exp typedNull() {
>> return null;
>> }
>>
>> public void call() {
>> ArrayList<String> list = typedNull();
>> }
>> }
>>
>> May I safely assume that the following error issued by
>> javac b117 is a bug, or am I missing a subtle issue
>> about intersection types?
>
> Well, it's a spec bug, but one that's already been identified:
> https://bugs.openjdk.java.net/browse/JDK-8028813
Thanks for the reference.
BTW, are there other open bugs against spec part G
that I should know about?
> What javac is trying to say is that it can't resolve the inference bounds. And this is consistent with the spec.
>
> When testing for applicability (18.5.1), we get these bounds (trivially):
> { t <: Object, exp <: Object, exp <: List<t> }
>
> And that can be resolved (18.4) to [ t:= Object, exp := List<Object> ]. (Note that exp depends on the resolution of t.)
>
> Then, for invocation type inference (18.5.2), we have an additional constraint:
> [ exp -> ArrayList<String> ]
>
> Giving us bounds:
> { t <: Object, exp <: ArrayList<String>, exp <: List<t> }
>
> It would be nice if we could then infer something about t... But we don't, and so resolution finds t := Object, and then there's no solution for exp.
I see I had a bug here. Just to double check: when we create fresh type variables
for t and exp (say z-t and z-exp) where z-exp has upper bounds ArrayList<String>
and List<z-t>: Is it a proper application of the well-formedness constraint in 18.4
to skip this solution candidate and continue?
> We're planning to come up with an extra incorporation rule that will handle cases like this.
Will you post on this list when a draft of the new rule is available?
thanks,
Stephan
More information about the lambda-spec-experts
mailing list