Skip to content

Commit

Permalink
Handle records in targetTypeMatches (#1061)
Browse files Browse the repository at this point in the history
Fixes #1059
  • Loading branch information
msridhar authored Oct 28, 2024
1 parent 8f4b928 commit dc9cf0e
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);
}
}
}

Expand Down

0 comments on commit dc9cf0e

Please sign in to comment.