Skip to content

Commit

Permalink
Support primitive static final fields as constant args in access paths (
Browse files Browse the repository at this point in the history
  • Loading branch information
msridhar authored Dec 21, 2024
1 parent b7dad0c commit f17b330
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ private AccessPathContext(ImmutableSet<String> immutableTypes) {
}

public boolean isStructurallyImmutableType(Type type) {
return immutableTypes.contains(type.tsym.toString());
return type.isPrimitive() || immutableTypes.contains(type.tsym.toString());
}

public static Builder builder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,18 @@ public void testVariablesInAccessPathsNegative() {
"import javax.annotation.Nullable;",
"public class Test {",
" private static final int INT_KEY = 42;", // Guaranteed constant!
" // Guaranteed constant after class loading",
" private static final int INT_KEY_HC = \"teststr\".hashCode();",
" public void testEnhancedFor(NullableContainer<String, NullableContainer<Integer, Object>> c) {",
" if (c.get(\"KEY_STR\") != null && c.get(\"KEY_STR\").get(INT_KEY) != null) {",
" c.get(\"KEY_STR\").get(INT_KEY).toString();",
" c.get(\"KEY_STR\").get(Test.INT_KEY).toString();",
" c.get(\"KEY_STR\").get(42).toString();", // Extra magic!
" }",
" if (c.get(\"KEY_STR\") != null && c.get(\"KEY_STR\").get(INT_KEY_HC) != null) {",
" c.get(\"KEY_STR\").get(INT_KEY_HC).toString();",
" c.get(\"KEY_STR\").get(Test.INT_KEY_HC).toString();",
" }",
" }",
"}")
.doTest();
Expand Down

0 comments on commit f17b330

Please sign in to comment.