Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash in ajava-based WPI related to captures #5335

Merged
merged 10 commits into from Sep 28, 2022
57 changes: 57 additions & 0 deletions checker/tests/ainfer-index/non-annotated/Dataset6Crash.java
@@ -0,0 +1,57 @@
// Test case for a WPI crash caused by mismatches between captured type variables
// and the declared type of a field: in particular, the issue is that base.next()
// the next field actually have slightly different types: base.next()'s type is
// a capture that extends T.

import java.util.Iterator;

public class Dataset6Crash {

public static <T> Iterator<T> limit(final Iterator<? extends T> base, final CountingPredicate<?
super T> filter) {
return new Iterator<T>() {

private T next;

private boolean end;

private int index = 0;

public boolean hasNext() {
return true;
}

public T next() {
fetch();
T r = next;
next = null;
return r;
}

private void fetch() {
if (next == null && !end) {
if (base.hasNext()) {
next = base.next();
if (!filter.apply(index++, next)) {
next = null;
end = true;
}
} else {
end = true;
}
}
}

public void remove() {
throw new UnsupportedOperationException();
}
};
}


private static class CountingPredicate<T> {
public boolean apply(int i, T next) {
return false;
}
}
}
@@ -0,0 +1,6 @@
public class TypeVarAssignment<T, S extends T> {
T t;
void foo(S s) {
t = s;
}
}
Expand Up @@ -858,6 +858,14 @@ private void printFailedInferenceDebugMessage(String reason) {
*/
private void updateAtmWithLub(AnnotatedTypeMirror sourceCodeATM, AnnotatedTypeMirror ajavaATM) {

if (sourceCodeATM.getKind() != ajavaATM.getKind()) {
// This can happen e.g. when recursing into the bounds of a type variable:
// the bound on sourceCodeATM might be a declared type (such as T), while
// the ajavaATM might be a typevar (such as S extends T), or vice-versa. In
// that case, use asSuper to make the two ATMs fully-compatible.
sourceCodeATM = AnnotatedTypes.asSuper(this.atypeFactory, sourceCodeATM, ajavaATM);
}

switch (sourceCodeATM.getKind()) {
case TYPEVAR:
updateAtmWithLub(
Expand Down