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:
@@ -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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user