Unused type variable causes type inference to fail
Issue #213
new
ExtendJ 8.0.1-195-gbd08c51 Java SE 8
Test case:
public abstract class Test {
String build() {
return buildIt();
}
abstract <T, U extends T> T buildIt();
}
Expected result: should compile without warning
Actual result:
[junit] tests/generics/method_20p/Test.java:4: error: return value must be an instance of java.lang.String which Unknown is not
[junit] tests/generics/method_20p/Test.java:4: error: no method named buildIt() in Test matches. However, there is a method buildIt()
Comments (1)
-
reporter - Log in to comment
The type inference in ExtendJ is implemented mostly following the specification for Java 5. As far as I know, the Java 7 specification is very similar for the type inference.
The type inference starts by looking at formal arguments. There are none in this case, so it goes on to 15.12.2.8. Inferring Unresolved Type Arguments.
The initial constraints in this step are:
String >> T
T >> U
U << T
These constraints are simplified to:
T <: String
U <: T
T :> U
Equality constraints are then resolved, but there are none in this case. Then, according to the specification, we should compute
T <: glb(String)
andU <: glb(T)
. However, the implementation in ExtendJ works differently here and usesU <: lub(T,U)
.