Skip to content

Commit

Permalink
ECJ fails: Problem detected during type inference: Unknown error at
Browse files Browse the repository at this point in the history
invocation of getReadOnly(P)

tentative fix for eclipse-jdt#2413
  • Loading branch information
stephan-herrmann committed May 16, 2024
1 parent eddfb7d commit 51d4520
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ private ConstraintTypeFormula[] typeArgumentEqualityConstraints(TypeBinding s, T
for (int i = 0; i < sis.length; i++) {
TypeBinding si = sis[i];
TypeBinding ti = tis[i];
if (si.isWildcard() || ti.isWildcard() || TypeBinding.equalsEquals(si, ti))
if (isOrContainsWildcard(si) || isOrContainsWildcard(ti) || TypeBinding.equalsEquals(si, ti))
continue;
result.add(ConstraintTypeFormula.create(si, ti, ReductionResult.SAME, isSoft));
}
Expand All @@ -984,6 +984,25 @@ private ConstraintTypeFormula[] typeArgumentEqualityConstraints(TypeBinding s, T
return null;
}

boolean isOrContainsWildcard(TypeBinding t) {
if (t.isWildcard()) return true;
class FindWildcard extends TypeBindingVisitor {
boolean found;

@Override
public boolean visit(ParameterizedTypeBinding parameterizedTypeBinding) {
if ((parameterizedTypeBinding.tagBits & TagBits.HasDirectWildcard) != 0) {
this.found = true;
return false;
}
return true;
}
}
FindWildcard visitor = new FindWildcard();
TypeBindingVisitor.visit(visitor, t);
return visitor.found;
}

/**
* Try to reduce the one given constraint.
* If a constraint produces further constraints reduce those recursively.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10864,4 +10864,31 @@ public class TestClass implements TestClass.Missing1<TestClass.Missing2<TestClas
""";
runner.runNegativeTest();
}
public void testGH2413() {
runConformTest(
new String[] {
"EjcBug2413.java",
"""
public class EjcBug2413 {
public interface EventSource<L> { }
public interface ObservableEventListener<V> { }
public interface WritableProperty<V> extends EventSource<ObservableEventListener<V>> {
static <P extends WritableProperty<?>> P getReadOnly(P property) {
return null;
}
}
public static class Property<V> implements EventSource<ObservableEventListener<V>>, WritableProperty<V> { }
public static abstract class Bug2413<V, P extends Property<V>> {
public void foo(P property) {
P readOnly = WritableProperty.getReadOnly(property);
}
}
}
"""});
}
}

0 comments on commit 51d4520

Please sign in to comment.