Skip to content

Commit

Permalink
Erroneous "Cannot infer type arguments" error
Browse files Browse the repository at this point in the history
fixes eclipse-jdt#1475

Implementation of JLS 15.9.3. failed to substitute an enclosing type in
 -  The return type of mj is θj applied to D<F1, ..., Fp>.
  • Loading branch information
stephan-herrmann committed Apr 7, 2024
1 parent 8cf2f7a commit 4e5b9e0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5382,7 +5382,9 @@ public TypeBinding substitute(TypeVariableBinding typeVariable) {
}
}
}
staticFactory.returnType = environment.createParameterizedType(genericType, Scope.substitute(substitution, genericType.typeVariables()), originalEnclosingType);
staticFactory.returnType = environment.createParameterizedType(genericType,
Scope.substitute(substitution, genericType.typeVariables()),
(ReferenceBinding) Scope.substitute(substitution, originalEnclosingType));
staticFactory.parameters = Scope.substitute(substitution, method.parameters);
staticFactory.thrownExceptions = Scope.substitute(substitution, method.thrownExceptions);
if (staticFactory.thrownExceptions == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10682,4 +10682,32 @@ public int getWeaveCount() {
"----------\n",
null, true, customOptions);
}
public void testGH1475() {
runConformTest(
new String[] {
"CannotInferTypeArguments.java",
"""
public class CannotInferTypeArguments<V extends java.util.concurrent.Semaphore> {
class Fish {
public V getFlavour() {
return null;
}
}
class Shark<E extends Fish> {
}
<E extends Fish> Shark<E> fish() {
// This compiles fine with javac, but will only work in Eclipse with new Shark<E>();
return new Shark<>();
}
<E extends Fish> Shark<E> fish2() {
Shark<E> s = new Shark<>();
return s;
}
}
"""
});
}
}

0 comments on commit 4e5b9e0

Please sign in to comment.