Skip to content

Commit

Permalink
SONARPY-2215 Document absence of types when CFG is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-dequenne-sonarsource committed Oct 24, 2024
1 parent e38877f commit 4477159
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ private Map<SymbolV2, Set<PythonType>> inferTypesAndMemberAccessSymbols(Tree sco

ControlFlowGraph cfg = controlFlowGraphSupplier.get();
if (cfg == null) {
// TODO SONARPY-2215: fix me
return Map.of();
}
assignedNames.addAll(annotatedParameterNames);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2656,6 +2656,16 @@ void typesBySymbol_declaration_without_assignment() {
assertThat(typesBySymbol).isEmpty();
}

@Test
void typeBySymbol_invalidCfg() {
// No types will be retrieved when the CFG is invalid
var typesBySymbol = inferTypesBySymbol("""
class A: ...
continue
""");
assertThat(typesBySymbol).isEmpty();
}

private static Map<SymbolV2, Set<PythonType>> inferTypesBySymbol(String lines) {
FileInput root = parse(lines);
var symbolTable = new SymbolTableBuilderV2(root).build();
Expand Down

0 comments on commit 4477159

Please sign in to comment.