Skip to content

Commit 450ec50

Browse files
Seppli11sonartech
authored andcommitted
SONARPY-3552 Testing behavior when there are conflicting class members (#689)
GitOrigin-RevId: f1c19657694ffe17d8c9afc90adf94249f3c3c95
1 parent 6b0ca3d commit 450ec50

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

python-frontend/src/test/java/org/sonar/python/semantic/v2/TypeInferenceV2Test.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,40 @@ class A:
774774
});
775775
}
776776

777+
@Test
778+
void conflictBetweenFunctionAndStaticField() {
779+
var code = """
780+
class A:
781+
something: int = 42
782+
def something(self): ...
783+
A
784+
""";
785+
Expression expr = lastExpression(code);
786+
assertThat(expr.typeV2())
787+
.isInstanceOfSatisfying(ClassType.class, classType -> {
788+
assertThat(classType.members())
789+
.containsExactlyInAnyOrder(
790+
new Member("something", ObjectType.fromType(INT_TYPE)),
791+
new Member("something", PythonType.UNKNOWN));
792+
// There should be a FunctionType, see SONARPY-3553 and SONARPY-3554
793+
});
794+
}
795+
796+
@Test
797+
void conflictBetweenFunctionDefinitions() {
798+
var code = """
799+
class A:
800+
def a(self): ...
801+
def a(self): ...
802+
A
803+
""";
804+
Expression expr = lastExpression(code);
805+
assertThat(expr.typeV2()).isInstanceOfSatisfying(ClassType.class, classType -> {
806+
assertThat(classType.members()).containsExactly(new Member("a", PythonType.UNKNOWN));
807+
// should resolve to the FunctionType, see SONARPY-3554 and SONARPY-3553
808+
});
809+
}
810+
777811
@Test
778812
void staticFieldsInInheritedClasses() {
779813
Expression exprWithInheritance = lastExpression("""

0 commit comments

Comments
 (0)