Skip to content

Commit

Permalink
feat(list-access): overwrite definition of indices if list is redefined
Browse files Browse the repository at this point in the history
When a list is redefined the former definiton is replaced, therefore storing the indices would cause
keeping the previous definition in the slice.
  • Loading branch information
Slartibartfass2 committed Dec 3, 2024
1 parent ed46dfa commit 3bc497c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/dataflow/environments/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ function defInEnv(newEnvironments: IEnvironment, name: string, definition: Ident
}

function mergeIndices(existing: IdentifierDefinition[], definition: InGraphIdentifierDefinition): InGraphIdentifierDefinition[] {
// When new definition is not a single index, e.g. a list redefinition, then reset existing definition
// TODO: what happens when indicesCollection has more than one element?
if(definition.indicesCollection !== undefined && definition.indicesCollection?.some(indices => !indices.isSingleIndex)) {
return [definition];
}
// console.log('merging');
const existingDefs = existing.map((def) => def as InGraphIdentifierDefinition).filter((def) => def !== undefined);
const indices = definition.indicesCollection?.flatMap(indices => indices.indices) ?? [];
// Compare existing and new definitions, add new definitions and remove existing
Expand Down
16 changes: 16 additions & 0 deletions test/functionality/slicing/pointer-analysis/list-access.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ result <- person`,
person$is_male <- FALSE
person$name <- "Alice"
person$age <- 33
result <- person`
);

assertSliced(
label('When whole list is redefined, then every list assignment before is not in slice', []), shell,
`person <- list(age = 24, name = "John")
person$age <- 33
person$name <- "Jane"
person <- list(height = 164, is_male = FALSE)
person$height <- 199
person$is_male <- TRUE
result <- person`,
['7@result'],
`person <- list(height = 164, is_male = FALSE)
person$height <- 199
person$is_male <- TRUE
result <- person`
);
});
Expand Down

0 comments on commit 3bc497c

Please sign in to comment.