Skip to content

ECJ 2025-12 fails inference with lower bounded wildcard while javac succeeds #4774

@coehlrich

Description

@coehlrich

With this:

public class Test {

	public static void main(String[] args) {
		Z<B> z = new Z<>(List.of(
				new Y<>(new A()),
				new Y<>(new B()),
				new Y<>(new C())));
	}
	
	public static record Z<T>(List<? extends X<? super T>> l) {}
	public static record Y<T>(T t) implements X<T> {}
	public static interface X<T> {}
	
	public static class A {}
	public static class B extends A {}
	public static class C extends B {}
}

ECJ fails to compile with Cannot infer type arguments for Z<> whilst Javac succeeds

While debugging this I noticed I noticed that <Z#0-T'#5 extends Z#1-T'#0> <: <Z#2-T'#1> (the upper bounds of Z#0-T'#5 are Z#1-T'#0, Z#2-T'#1, Z#3-T'#2) is reduced to false since isSubtypeOf isn't overriden by CaptureBinding18 so only the first bound is checked and that test2.Test.Y<Z#1-T'#0> <: test2.Test.X<? super Z#1-T'#0&Z#2-T'#1&Z#3-T'#2> is also reduced to false since currently TypeBinding.isTypeArgumentContainedBy only checks the lower bound.

With those 2 issues fixed ECJ then resolves E#4 to Test.Y<? extends java.lang.Object> since there is no ? super wildcard in the lower bounds for JLS §4.10.4 to output a ? super wildcard and without the z captures ECJ resolves E#4 to have a lower bound of Test.Y<? extends Test.A> for the same reason.

@stephan-herrmann

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcompilerEclipse Java Compiler (ecj) related issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions