Skip to content

Commit

Permalink
Array assignment merges safety rather than replacing it (#2154)
Browse files Browse the repository at this point in the history
Array assignment merges safety rather than replacing it
  • Loading branch information
carterkozak authored Mar 31, 2022
1 parent 0fed88d commit 9f7b4a5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,9 @@ public TransferResult<Safety, AccessPathStore<Safety>> visitAssignment(
if (target instanceof LocalVariableNode) {
updates.trySet(target, safety);
} else if (target instanceof ArrayAccessNode) {
updates.trySet(((ArrayAccessNode) target).getArray(), safety);
Node arrayNode = ((ArrayAccessNode) target).getArray();
Safety arrayCombinedSafety = input.getValueOfSubNode(arrayNode).leastUpperBound(safety);
updates.trySet(arrayNode, arrayCombinedSafety);
} else if (target instanceof FieldAccessNode) {
FieldAccessNode fieldAccess = (FieldAccessNode) target;
updates.set(fieldAccess, safety);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,10 @@ public void testArraySafety() {
" // BUG: Diagnostic contains: Dangerous argument value: arg is 'DO_NOT_LOG' "
+ "but the parameter requires 'SAFE'.",
" fun(one);",
" one[2] = safeParam;",
" // BUG: Diagnostic contains: Dangerous argument value: arg is 'DO_NOT_LOG' "
+ "but the parameter requires 'SAFE'.",
" fun(one);",
" // BUG: Diagnostic contains: Dangerous argument value: arg is 'DO_NOT_LOG' "
+ "but the parameter requires 'SAFE'.",
" fun(new Object[] {safeParam, unsafeParam, dnlParam});",
Expand Down
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-2154.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Array assignment merges safety rather than replacing it
links:
- https://github.com/palantir/gradle-baseline/pull/2154

0 comments on commit 9f7b4a5

Please sign in to comment.