From 44771593c89564d0bcb9499fc6891cfae07d2d7f Mon Sep 17 00:00:00 2001 From: Guillaume Dequenne Date: Thu, 24 Oct 2024 09:19:03 +0200 Subject: [PATCH] SONARPY-2215 Document absence of types when CFG is invalid --- .../org/sonar/python/semantic/v2/TypeInferenceV2.java | 1 - .../sonar/python/semantic/v2/TypeInferenceV2Test.java | 10 ++++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/python-frontend/src/main/java/org/sonar/python/semantic/v2/TypeInferenceV2.java b/python-frontend/src/main/java/org/sonar/python/semantic/v2/TypeInferenceV2.java index 3a08945b40..2bc343086c 100644 --- a/python-frontend/src/main/java/org/sonar/python/semantic/v2/TypeInferenceV2.java +++ b/python-frontend/src/main/java/org/sonar/python/semantic/v2/TypeInferenceV2.java @@ -130,7 +130,6 @@ private Map> inferTypesAndMemberAccessSymbols(Tree sco ControlFlowGraph cfg = controlFlowGraphSupplier.get(); if (cfg == null) { - // TODO SONARPY-2215: fix me return Map.of(); } assignedNames.addAll(annotatedParameterNames); diff --git a/python-frontend/src/test/java/org/sonar/python/semantic/v2/TypeInferenceV2Test.java b/python-frontend/src/test/java/org/sonar/python/semantic/v2/TypeInferenceV2Test.java index 6b1222d38e..07aaf50683 100644 --- a/python-frontend/src/test/java/org/sonar/python/semantic/v2/TypeInferenceV2Test.java +++ b/python-frontend/src/test/java/org/sonar/python/semantic/v2/TypeInferenceV2Test.java @@ -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> inferTypesBySymbol(String lines) { FileInput root = parse(lines); var symbolTable = new SymbolTableBuilderV2(root).build();