Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 242159

Summary: [1.7][compiler] type inference with unbounded wildcard in result type
Product: [Eclipse Project] JDT Reporter: Christopher Sahnwaldt <jcsahnwaldt>
Component: CoreAssignee: Srikanth Sankaran <srikanth_sankaran>
Status: VERIFIED FIXED QA Contact:
Severity: minor    
Priority: P3 CC: amj87.iitr, deepakazad, gk_brown, jcsahnwaldt, Mike_Wilson, Olivier_Thomann, philippe_mulet, zorzella
Version: 3.5   
Target Milestone: 3.7.1   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Patch under consideration.
none
Revised cumulative patch under consideration. none

Description Christopher Sahnwaldt CLA 2008-07-26 17:48:21 EDT
Build ID: I20080617-2000

Steps To Reproduce:
While playing around with bug 118273, I stumbled upon something that looks like another bug to me.

class X<A>
{
  <B extends Comparable<B>> X<B> bar()
  {
    return null;
  }

  void foo()
  {
    X raw = bar();     //1 accepted
    X<?> wild = bar(); //2 rejected
  }
}

The Eclipse compiler accepts line //1, but rejects line //2 with the error message:

Bound mismatch: The generic method bar() of type X<A> is not applicable for the arguments (). The inferred type Comparable<Comparable<B>> is not a valid substitute for the bounded parameter <B extends Comparable<B>>

Note: javac 1.6.0_05 infers B=Object for both lines and rejects them, which according to bug 118273 is incorrect at least for line //1.
Comment 1 Philipe Mulet CLA 2008-11-07 05:39:29 EST
Added GenericTypeTest#test1404
Comment 2 Mike Wilson CLA 2009-05-05 10:13:06 EDT
Changing version tag to something more believable.
Comment 3 Srikanth Sankaran CLA 2011-05-24 19:24:36 EDT
See that this code compiles with JDK 7b138.
Eclipse will shortly be fixing this issue
and the fix will be made available only via
a Java7 enabled release. Changed defect title
to reflect that.
Comment 4 Srikanth Sankaran CLA 2011-05-25 01:59:48 EDT
Created attachment 196508 [details]
Patch under consideration.

This is a cumulative patch and includes also the changes being
considered for bug 341795. The code changes inside org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding.resolveSubstituteConstraints(Scope, TypeVariableBinding[], InferenceContext, boolean)
are for the bug 341795. Other changes are for bug 242159

This patch is under test.
Comment 5 Srikanth Sankaran CLA 2011-05-25 03:26:12 EDT
Passes all JDT/Core tests. I'll play around with it some more
before releasing it.
Comment 6 Srikanth Sankaran CLA 2011-05-26 04:42:15 EDT
Created attachment 196638 [details]
Revised cumulative patch under consideration.

This is a cleaner, better documented patch.
Comment 7 Srikanth Sankaran CLA 2011-05-26 06:11:11 EDT
As a part of this cumulative fix, I had to remaster 13 tests from
GenericTypeTests suite - I have verified that in every one of these
cases, the new behavior matches JDK 7b142 - javac compiler.

The fix applies to all compliance levels.

Released in BETA_JAVA7 branch only - this is too late for 3.7
stream (HEAD)
Comment 8 Srikanth Sankaran CLA 2011-05-30 01:03:04 EDT
*** Bug 283353 has been marked as a duplicate of this bug. ***
Comment 9 Srikanth Sankaran CLA 2011-06-02 03:39:45 EDT
(In reply to comment #6)
> Created attachment 196638 [details]
> Revised cumulative patch under consideration.
> 
> This is a cleaner, better documented patch.

For posterity, this patch was superceded by the fix for
bug 347600, which is a better more general fix.
Comment 10 Deepak Azad CLA 2011-07-19 08:18:48 EDT
Verified with v20110714-1300.
Comment 11 Srikanth Sankaran CLA 2011-11-13 23:21:51 EST
*** Bug 351717 has been marked as a duplicate of this bug. ***