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

Handle records in targetTypeMatches #1061

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
// 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