ContextAnalysis: Track local variables and function parameters separately.

This enables us to add all local variable Definitions to the DAST so that downstream visitors don't need to compute the local variables of a function again.
This commit is contained in:
2023-03-22 23:22:36 +01:00
parent 9751a1da2f
commit c5c01041e4
10 changed files with 130 additions and 129 deletions

View File

@@ -92,4 +92,28 @@ public class FunctionDefinitionTest {
var e = assertThrows(RuntimeException.class, () -> ctxAnal.visit(tree));
assertEquals("Error in line 1:31 Parameter name Bar duplicates an enum of the same name.", e.getMessage());
}
@Test
void shouldResetVariablesAndParameterEnvironment() {
// given
var tree = Helper.prepareParser("""
function foo(x: int): int {
return 1;
}
function bar(): int {
let x: int = 0;
return x;
}
bar();
""");
var ctxAnal = new ContextAnalysis(
Helper.getFuncs(tree),
Helper.getStructs(tree),
Helper.getEnums(tree)
);
// when / then
assertDoesNotThrow(() -> ctxAnal.visit(tree));
}
}