Skip to content
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-1815 Enable AST-based type inference for functions/module containing try/catch blocks #1792

Merged
merged 2 commits into from May 13, 2024

Conversation

guillaume-dequenne-sonarsource
Copy link
Contributor

No description provided.

workList.push(expression);
while (!workList.isEmpty()) {
Expression e = workList.pop();
if (e.is(Tree.Kind.NAME)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is possible to do type check and type cast in single operation here:

if (e instanceof Name name) {
...
}


public record Assignment(SymbolV2 lhsSymbol, Name lhsName, Expression rhs) {
public class Assignment {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need to have it as a class instead of a record?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion on what it should be, but if you don't mind, I'd rather keep this as it is here, since SONARPY-1826 refactors this again. Please have a look at that PR and I'm happy to further refactor it there into a record if that still makes sense (I didn't consider this tbh).

final SymbolV2 lhsSymbol;
Name lhsName;
Expression rhs;
Set<SymbolV2> variableDependencies = new HashSet<>();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to have a single place to initialize everything. If you have a constructor - may be it makes sense to initialize these fields there as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't mind I'll address this as part of SONARPY-1826.

void computeDependencies(Expression expression, Set<SymbolV2> trackedVars) {
Deque<Expression> workList = new ArrayDeque<>();
workList.push(expression);
while (!workList.isEmpty()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment here to rework this part later. Add tests showing type tracking of collection item types

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't add the comment, as I think we already have some tickets that relate to this anyway. However, I added a test that shows that collection item types actually work (for a trivial case).

Set<Assignment> workSet = new HashSet<>(propagations);
while (!workSet.isEmpty()) {
Iterator<Assignment> iterator = workSet.iterator();
Assignment propagation = iterator.next();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to assignment and propagations parameter as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be updated in SONARPY-1826 (introducing Propagation class again).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just couple of small changes requested

Copy link

Quality Gate failed Quality Gate failed

Failed conditions
15 New issues

See analysis details on SonarQube

Catch issues before they fail your Quality Gate with our IDE extension SonarLint SonarLint

Base automatically changed from SONARPY-1818 to MMF-3796 May 13, 2024 14:32
@guillaume-dequenne-sonarsource guillaume-dequenne-sonarsource marked this pull request as ready for review May 13, 2024 14:34
@guillaume-dequenne-sonarsource guillaume-dequenne-sonarsource merged commit 081dc4a into MMF-3796 May 13, 2024
0 of 8 checks passed
guillaume-dequenne-sonarsource added a commit that referenced this pull request May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants