-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SONARPY-2382 fix unary propagation problem #2198
Conversation
6d38e69
to
370b97e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, well done 💪
I left a minor comment on the test
(~s)(X) # Ok |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor I find it not explicit what you want to test here. What matters is not really the fact that s
is unknown but that there is a unary ~ operator applied on s
right?
I suggest adding a test in nonCallableCalled
called def callable_with_unary_operator
and checking that not issue are raised when +,-,~...
are applied
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that I read the all PR I understand why you called the test function like this. Still, I think it will be clearer for someone who hasn't the context to rewrite this test to be more explicit
private PythonType calculateUnaryExprType(UnaryExpression unaryExpr) { | ||
String operator = unaryExpr.operator().value(); | ||
return TypeUtils.map(unaryExpr.expression().typeV2(), type -> mapUnaryExprType(operator, type)); | ||
} | ||
|
||
private PythonType mapUnaryExprType(String operator, PythonType type) { | ||
return switch (operator) { | ||
case "~" -> mapInvertExprType(type); | ||
// not cannot be overloaded and always returns a boolean | ||
case "not" -> boolType; | ||
case "+", "-" -> mapUnaryPlusMinusType(type); | ||
default -> PythonType.UNKNOWN; | ||
}; | ||
} | ||
|
||
private PythonType mapInvertExprType(PythonType type) { | ||
if(isIntTypeCheck.check(type) == TriBool.TRUE || isBooleanTypeCheck.check(type) == TriBool.TRUE) { | ||
return intType; | ||
} | ||
return PythonType.UNKNOWN; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clean implementation, well done 💪
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx 😊
|
||
expr.accept(trivialTypePropagationVisitor); | ||
assertThat(expr.typeV2()).isEqualTo(PythonType.UNKNOWN); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit add the extra line there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I'm impartial whether there is a line there or not. However, I've definitely removed lines between the last function and the closing curly bracket of the class. Is this style documented?
0f77bbd
to
135ee31
Compare
135ee31
to
7607d5b
Compare
Quality Gate passedIssues Measures |
SONARPY-2382