-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[Linter] Checks for explicit self-assignments. #17124
[Linter] Checks for explicit self-assignments. #17124
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
let x = 5; | ||
let y = 10; |
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.
Could this be extended to handle, e.g., let (x, y) = (x, y)
?
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.
let (x, y) = (x, y)
does not work in sui move. Tuple only appear in expressions (usually in the return position for a function)
if let UnannotatedExp_::Copy { | ||
var: sp!(_, rhs), .. | ||
} = &assign_exp.exp.value |
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.
Should this also handle the Move
case?
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.
refactored
8dacc61
to
fa45b94
Compare
@tx-tomcat is attempting to deploy a commit to the Mysten Labs Team on Vercel. A member of the Team first needs to authorize it. |
cacbaa6
to
d3bbf5f
Compare
d3bbf5f
to
e8aa4ef
Compare
let diag = diag!(SELF_ASSIGNMENT_DIAG, (loc, msg)); | ||
self.env.add_diag(diag); | ||
} | ||
} |
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.
The function takes three parameters:
&mut self:
A mutable reference to the struct this method belongs to.
value_list:
A reference to an LValueList, which likely contains the left-hand side of the assignment.
assign_exp
: A reference to the right-hand side of the assignment.
loc
: A Loc value, probably representing the location of this assignment in the source code.
It first checks if the assign_exp
is an ExpList
(a list of expressions).
If it is, it then checks for self-assignment by iterating over the left-hand side values (value_list.value
) and the right-hand side expressions (rhs_expressions
) simultaneously.
For each pair, it checks if:
The left-hand side is a LValue_::Var
.
The right-hand side is a Single
expression.
The right-hand side expression is either a Copy
or Move
operation.
The variable being copied or moved on the right side is the same as the variable on the left side.
If all pairs in the assignment satisfy these conditions, is_self_assignment
is set to true.
e8aa4ef
to
bc40896
Compare
Description
This code implements a linter check to detect self-assignments in Move code.
The check focuses on two types of expressions:
*a = b
)a = b
)In each case, the compiler tracks for the same "memory locations" of the assignment, attempting to track the same local variable. It does not have any sort of aliasing notion nor does it track references in any meaningful way.
Test plan
Added more use case
Release notes