File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed
main/java/org/sonar/python/semantic/v2
test/java/org/sonar/python/semantic/v2 Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change 25
25
import java .util .stream .IntStream ;
26
26
import org .sonar .python .semantic .ProjectLevelSymbolTable ;
27
27
import org .sonar .python .types .v2 .ModuleType ;
28
+ import org .sonar .python .types .v2 .ObjectType ;
28
29
import org .sonar .python .types .v2 .PythonType ;
29
30
30
31
public class ProjectLevelTypeTable {
@@ -65,6 +66,9 @@ public PythonType getType(List<String> typeFqnParts) {
65
66
var parent = (PythonType ) rootModule ;
66
67
for (int i = 0 ; i < typeFqnParts .size (); i ++) {
67
68
var part = typeFqnParts .get (i );
69
+ if (parent instanceof ObjectType ) {
70
+ return PythonType .UNKNOWN ;
71
+ }
68
72
Optional <PythonType > resolvedMember = parent .resolveMember (part );
69
73
if (resolvedMember .isPresent ()) {
70
74
parent = resolvedMember .get ();
Original file line number Diff line number Diff line change @@ -2356,6 +2356,16 @@ void basic_imported_symbols() {
2356
2356
assertThat (((UnionType ) mathModule .resolveMember ("acos" ).get ()).candidates ()).allMatch (FunctionType .class ::isInstance );
2357
2357
}
2358
2358
2359
+ @ Test
2360
+ // TODO SONARPY-2176 ProjectLevelSymbolTable#getType should be able to resolve types when there is a conflict between a member and a subpackage
2361
+ void import_conflict_between_member_and_submodule () {
2362
+ var statement = lastExpression ("""
2363
+ import opentracing.tracer.Tracer as ottt
2364
+ ottt
2365
+ """ );
2366
+ assertThat (statement .typeV2 ()).isInstanceOf (UnknownType .class );
2367
+ }
2368
+
2359
2369
@ Test
2360
2370
void isInstanceTests () {
2361
2371
var xType = lastExpression ("""
You can’t perform that action at this time.
0 commit comments