Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 347145 - [1.7][compiler] Bounds check issue with raw types in method inference
Summary: [1.7][compiler] Bounds check issue with raw types in method inference
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.7.1   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-25 09:05 EDT by Srikanth Sankaran CLA
Modified: 2011-08-05 02:54 EDT (History)
3 users (show)

See Also:


Attachments
Early version of a fix. (3.98 KB, patch)
2011-05-29 08:43 EDT, Srikanth Sankaran CLA
no flags Details | Diff
Revised patch under test (5.47 KB, patch)
2011-05-29 23:14 EDT, Srikanth Sankaran CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Srikanth Sankaran CLA 2011-05-25 09:05:21 EDT
The following program has started compiling with out any
errors on 1.7 (JDK 7b142 compiles this).


class A {}
class B<V> extends A {} 
class F<T extends A, Y extends B<T>> {
	static <U extends A , V extends B<U>> F<U,V> g() {
		return null;
	}
}
public class X  {
    F<? extends B, ? extends B<? extends B>> f011 = F.g();
}

It used to fail to compile with JDK 6 with the message:

X.java:9: incompatible types; inferred type argument(s) B,B<? extends B> do not
conform to bounds of type variable(s) U,V
found   : <U,V>F<U,V>
required: F<? extends B,? extends B<? extends B>>
    F<? extends B, ? extends B<? extends B>> f011 = F.g();
                                                       ^
1 error

JDK5 compiles this alright.

Eclipse top of trunk BETA_JAVA7 fails with a message:
Bound mismatch: The generic method g() of type F<T,Y> is not applicable for the arguments (). The inferred type B<? extends B>&B<B> is not a valid substitute for the bounded parameter <V extends 
	 B<U>>

This difference needs to be understood as in the context of java 7 this
impacts <> usage also.
Comment 1 Srikanth Sankaran CLA 2011-05-25 09:06:07 EDT
I'll investigate this.
Comment 2 Srikanth Sankaran CLA 2011-05-26 01:04:45 EDT
Released disabled junit org.eclipse.jdt.core.tests.compiler.regression.GenericsRegressionTest._test347145() into BETA_JAVA7 branch.
Comment 3 Srikanth Sankaran CLA 2011-05-26 10:39:42 EDT
(In reply to comment #0)
> The following program has started compiling with out any
> errors on 1.7 (JDK 7b142 compiles this).

[...]
 
> It used to fail to compile with JDK 6 with the message:

Olivier, can you check against different versions of JDK7
to have to see when exactly this started compiling alright ?

(My hard-disk got replaced and I lost my cache of past builds
of javac. (In any case, I had them only from 7b75 or so)) - TIA.
Comment 4 Srikanth Sankaran CLA 2011-05-29 08:43:04 EDT
Created attachment 196844 [details]
Early version of a fix.
Comment 5 Srikanth Sankaran CLA 2011-05-29 23:14:15 EDT
Created attachment 196864 [details]
Revised patch under test
Comment 6 Srikanth Sankaran CLA 2011-05-29 23:47:44 EDT
(In reply to comment #3)

> Olivier, can you check against different versions of JDK7
> to have to see when exactly this started compiling alright ?

Please ignore this request - I have figured out what the problem
is: The error message offers a good clue as to what is happening
here:

"The inferred type B<? extends B>&B<B> is not a valid substitute
for the bounded parameter <V extends B<U>>"

The intersection type "B<? extends B>&B<B>" looks strange. Why
isn't simply B<B> since B<? extends B> is a superset if B<B> ?
This is because after one round, we infer 

   <U extends A>  to be B#RAW
   <V extends B<U>> to be B<? extends B#RAW>&B<U>

At this point neither of the intersecting types look like a subset
of the other. However once we remove the lingering reference to U
the intersecting types become "B<? extends B>&B<B>" with a clear
subset relationship.

The fix is to recognize the fact after we apply the final round of
substitutions to remove any lingering type variable references, we
should re-evaluate intersection types suitably.
Comment 7 Srikanth Sankaran CLA 2011-05-30 00:39:12 EDT
Released in BETA_JAVA7 branch. Olivier, please review - TIA.
Comment 8 Srikanth Sankaran CLA 2011-05-31 04:53:15 EDT
(In reply to comment #6)

> The fix is to recognize the fact after we apply the final round of
> substitutions to remove any lingering type variable references, we
> should re-evaluate intersection types suitably.

And propagate the altered type back to the inference context. 
See bug 347746.
Comment 9 Srikanth Sankaran CLA 2011-06-02 00:53:07 EDT
Please ignore this code review request, This fix is being subsumed by
the better fix being tested for bug 347600 for which I will
raise a separate code review request.
Comment 10 Satyam Kandula CLA 2011-07-01 08:50:16 EDT
Verified using Eclipse Java 7 Support(Beta) feature patch v20110623-0900.