Bug 80144 - [1.5] Mutually-recursive type bounds interfere with inheritance of generic type
Summary: [1.5] Mutually-recursive type bounds interfere with inheritance of generic type
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Linux
: P3 major (vote)
Target Milestone: 3.1 M4   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-03 14:32 EST by John Maraist CLA
Modified: 2004-12-14 23:00 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Maraist CLA 2004-12-03 14:32:23 EST
Using eclipse I20041201 on Mandrake linux. 
 
This first bit of code gives the message "Bounds mismatch: The generic method 
frenchify(Collection<? extends Phi<AA,BB>>, AA) of type Problem<A,B,P> is not 
applicable for the arguments (Collection<? extends Phi<A,BB>>, A) since the 
type A is not a valid substitute for the bounded parameter <AA extends 
Alpha<AA,BB>>."  In fact, in that use of the static method, A and B are the 
substitutes for AA and BB. 
 
==================================================================== 
 
import java.util.ArrayList; 
 
interface Alpha<A1 extends Alpha<A1,B1>, B1 extends Beta<A1,B1>> { } 
interface Beta<A2 extends Alpha<A2,B2>, B2 extends Beta<A2,B2>> { } 
interface Phi<A3 extends Alpha<A3,B3>, B3 extends Beta<A3,B3>> { 
  public void latinize(A3 s); 
} 
 
public class Problem 
	<A extends Alpha<A,B>, B extends Beta<A,B>, P extends Phi<A,B>> 
  extends ArrayList<P> 
  implements Phi<A,B> { 
	public final void latinize(A a) { frenchify(this, a); } 
  // ----------------------------------------------------------------- 
  public static final <AA extends Alpha<AA,BB>, BB extends Beta<AA,BB>> 
    void frenchify(Collection<? extends Phi<AA,BB>> phis, AA aa) { 
	for(final Phi<AA,BB> phi : phis)  phi.latinize(aa); 
  } 
} 
 
==================================================================== 
 
Note that this problem goes away when Alpha is not mutually recursive with 
other type bound: 
 
==================================================================== 
import java.util.ArrayList; 
import java.util.Collection; 
 
interface Gamma<G1 extends Gamma<G1>> { } 
interface Psi<GP extends Gamma<GP>> { public void germanize(GP s); } 
 
public class Working<A extends Gamma<A>, P extends Psi<A>> 
		extends ArrayList<P> 
		implements Psi<A> { 
 
  public final void germanize(A a) { anglicize(this, a); } 
  // ----------------------------------------------------------------- 
  public static final <AA extends Gamma<AA>> 
    void anglicize(Collection<? extends Psi<AA>> psis, AA aa) { 
		for(final Psi<AA> psi : psis) 
			psi.germanize(aa); 
  } 
} 
==================================================================== 
 
All of these classes compile without error or warning on javac.
Comment 1 Philipe Mulet CLA 2004-12-05 08:32:46 EST
Reproduced in latest
Comment 2 Philipe Mulet CLA 2004-12-05 18:34:41 EST
Added regression test: GenericTypeTest#test433.
Problem was in type inference algorithm which wasn't properly collecting
substitutes for '? extends Phi<AA,BB>' using 'Problem<A,B,P>'.

Allowed generic type to play correctly (as opposed to only parameterized types).
Also tuned #findSuperTypeErasingTo for type variables, since they cannot use
their erasure which is already a supertype.

Fixed
Comment 3 Olivier Thomann CLA 2004-12-14 23:00:17 EST
Verified in 200412140800