Skip to content

Commit

Permalink
Add missing override to RestoreNullnessAnnotationsVisitor (#1154)
Browse files Browse the repository at this point in the history
We missed the case for `ForAll` types (for generic methods)

Fixes #1129
  • Loading branch information
msridhar authored Mar 4, 2025
1 parent 0888040 commit baf8f77
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ public Type visitTypeVar(Type.TypeVar t, Type other) {
return updated != null ? updated : t;
}

@Override
public Type visitForAll(Type.ForAll t, Type other) {
Type methodType = t.qtype;
Type otherMethodType = ((Type.ForAll) other).qtype;
Type newMethodType = visit(methodType, otherMethodType);
if (methodType == newMethodType) {
return t;
} else {
return new Type.ForAll(t.tvars, newMethodType);
}
}

/**
* Updates the nullability annotations on a type {@code t} based on the nullability annotations
* on a type variable {@code other}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2258,6 +2258,26 @@ public void issue1126() {
.doTest();
}

@Test
public void issue1129() {
makeHelper()
.addSourceLines(
"Test.java",
"package com.uber;",
"import org.jspecify.annotations.Nullable;",
"import java.util.function.Consumer;",
"class Test {",
" interface BodySpec<B, S extends BodySpec<B, S>> {",
" <T extends S> T value(Consumer<@Nullable B> consumer);",
" }",
" abstract class DefaultBodySpec<B, S extends BodySpec<B, S>> implements BodySpec<B, S> {",
" @Override",
" public abstract <T extends S> T value(Consumer<@Nullable B> consumer);",
" }",
"}")
.doTest();
}

private CompilationTestHelper makeHelper() {
return makeTestHelperWithArgs(
Arrays.asList(
Expand Down

0 comments on commit baf8f77

Please sign in to comment.