Skip to content

Commit baf8f77

Browse files
authored
Add missing override to RestoreNullnessAnnotationsVisitor (#1154)
We missed the case for `ForAll` types (for generic methods) Fixes #1129
1 parent 0888040 commit baf8f77

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

nullaway/src/main/java/com/uber/nullaway/generics/TypeSubstitutionUtils.java

+12
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@ public Type visitTypeVar(Type.TypeVar t, Type other) {
120120
return updated != null ? updated : t;
121121
}
122122

123+
@Override
124+
public Type visitForAll(Type.ForAll t, Type other) {
125+
Type methodType = t.qtype;
126+
Type otherMethodType = ((Type.ForAll) other).qtype;
127+
Type newMethodType = visit(methodType, otherMethodType);
128+
if (methodType == newMethodType) {
129+
return t;
130+
} else {
131+
return new Type.ForAll(t.tvars, newMethodType);
132+
}
133+
}
134+
123135
/**
124136
* Updates the nullability annotations on a type {@code t} based on the nullability annotations
125137
* on a type variable {@code other}.

nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java

+20
Original file line numberDiff line numberDiff line change
@@ -2258,6 +2258,26 @@ public void issue1126() {
22582258
.doTest();
22592259
}
22602260

2261+
@Test
2262+
public void issue1129() {
2263+
makeHelper()
2264+
.addSourceLines(
2265+
"Test.java",
2266+
"package com.uber;",
2267+
"import org.jspecify.annotations.Nullable;",
2268+
"import java.util.function.Consumer;",
2269+
"class Test {",
2270+
" interface BodySpec<B, S extends BodySpec<B, S>> {",
2271+
" <T extends S> T value(Consumer<@Nullable B> consumer);",
2272+
" }",
2273+
" abstract class DefaultBodySpec<B, S extends BodySpec<B, S>> implements BodySpec<B, S> {",
2274+
" @Override",
2275+
" public abstract <T extends S> T value(Consumer<@Nullable B> consumer);",
2276+
" }",
2277+
"}")
2278+
.doTest();
2279+
}
2280+
22612281
private CompilationTestHelper makeHelper() {
22622282
return makeTestHelperWithArgs(
22632283
Arrays.asList(

0 commit comments

Comments
 (0)