Visitar URL original
Java: VariableAssign (LocalVariableDeclExpr) is not an Assignment · Issue #3266 · github/codeql · GitHub
The Wayback Machine - https://web.archive.org/web/20240131103502/https://github.com/github/codeql/issues/3266
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

Java: VariableAssign (LocalVariableDeclExpr) is not an Assignment #3266

Open
Marcono1234 opened this issue Apr 14, 2020 · 3 comments · May be fixed by #15451
Open

Java: VariableAssign (LocalVariableDeclExpr) is not an Assignment #3266

Marcono1234 opened this issue Apr 14, 2020 · 3 comments · May be fixed by #15451
Labels
Java question Further information is requested

Comments

@Marcono1234
Copy link
Contributor

The Assignment class is described as:

A common super-class that represents all varieties of assignments.

However, it appears that where a VariableAssign is initializing a local variable (and therefore is an instance of LocalVariableDeclExpr), it is not considered an Assignment.

Sorry if I am understand something wrong here, but this appears to be pretty irritating.

@Marcono1234 Marcono1234 added the question Further information is requested label Apr 14, 2020
@aschackmull
Copy link
Contributor

You are correct that Assignment only includes AssignExpr (like x = y) and AssignOp (like x += y), but neither variable initializations (like int x = y) nor unary updates (like x++). This is the reason why the classes VariableAssign and VariableUpdate also exists, so that you should be able to pick the one that covers the cases you're interested in. And if the subset of operations you're interested in isn't exactly covered by one of these, it's also easy to make your own class (see e.g. the definitions of VariableAssign and VariableUpdate).

@Marcono1234
Copy link
Contributor Author

Thank you for the clarification. Would it be possible to clarify that in the Assignment doc then and possibly link to VariableUpdate?

neither variable initializations

Field initializations are Assignments, though I guess you only meant local variable initializations?

@aschackmull
Copy link
Contributor

Yes, the doc could be a bit clearer. Yes, I was just referring to local variables, the reason for field initializations being Assignments is that those initializations happen inside the special object initializer method (or static initializer method for static fields).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Java question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants