Skip to content

Commit

Permalink
Handle records in targetTypeMatches
Browse files Browse the repository at this point in the history
  • Loading branch information
msridhar committed Oct 27, 2024
1 parent d6b7fa3 commit e089b06
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,27 @@ public void recordDeconstructionPatternSwitchCase() {
"}")
.doTest();
}

@Test
public void issue1059() {
defaultCompilationHelper
.addSourceLines(
"BarEntity.java",
"package com.uber;",
"import org.jspecify.annotations.NonNull;",
"import org.jspecify.annotations.Nullable;",
"public class BarEntity {",
" public interface Identifiable<ID> {",
" @Nullable",
" ID id();",
" }",
" public static class Id {}",
" public record NameChanged(BarEntity.Id id, Class<BarEntity> type) implements Identifiable<@NonNull Id> {",
" public NameChanged(BarEntity.Id id) {",
" this(id, BarEntity.class);",
" }",
" }",
"}")
.doTest();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,13 @@ private static boolean targetTypeMatches(Symbol sym, TypeAnnotationPosition posi
// on other types in the signature (e.g. `class Foo extends Bar<@A Baz> {}`).
return false;
default:
throw new AssertionError("unsupported element kind " + sym.getKind() + " symbol " + sym);
// Compare with toString() to preserve compatibility with JDK 11
if (sym.getKind().toString().equals("RECORD")) {
// Records are treated like classes
return false;
} else {
throw new AssertionError("unsupported element kind " + sym.getKind() + " symbol " + sym);

Check warning on line 378 in nullaway/src/main/java/com/uber/nullaway/NullabilityUtil.java

View check run for this annotation

Codecov / codecov/patch

nullaway/src/main/java/com/uber/nullaway/NullabilityUtil.java#L378

Added line #L378 was not covered by tests
}
}
}

Expand Down

0 comments on commit e089b06

Please sign in to comment.