Skip to content

Commit 90e8d71

Browse files
authored
fix: workaround compiler span mismatch in compound assignments (#114)
1 parent ca94e09 commit 90e8d71

File tree

5 files changed

+213
-99
lines changed

5 files changed

+213
-99
lines changed

move-mutator/src/mutate.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,29 @@ fn traverse_function(
187187
fn parse_expression_and_find_mutants(function: &FunctionEnv<'_>, exp: &ExpData) -> Vec<Mutant> {
188188
let convert_exps_to_explocs = |exps: &[Exp]| -> Vec<ExpLoc> {
189189
exps.iter()
190-
.map(|e| ExpLoc {
191-
exp: e.clone(),
192-
loc: function.module_env.env.get_node_loc(e.node_id()),
190+
.map(|e| {
191+
// NOTE: This is a workaround for a compiler bug.
192+
// For Deref operations in compound assignments, the Move compiler seems to
193+
// assign the span of the entire compound assignment to the Deref node.
194+
// We use the inner expression's location instead to get the correct span.
195+
//
196+
// TODO: When https://github.com/aptos-labs/aptos-core/pull/17841 is in a release branch,
197+
// we can remove the loc var and only leave "function.module_env.env.get_node_loc(e.node_id())"
198+
// for the "loc" field. Then update the deps to use the new release branch.
199+
let loc = if let ExpData::Call(_, Operation::Deref, inner_exps) = e.as_ref() {
200+
if let Some(inner_exp) = inner_exps.first() {
201+
function.module_env.env.get_node_loc(inner_exp.node_id())
202+
} else {
203+
function.module_env.env.get_node_loc(e.node_id())
204+
}
205+
} else {
206+
function.module_env.env.get_node_loc(e.node_id())
207+
};
208+
209+
ExpLoc {
210+
exp: e.clone(),
211+
loc,
212+
}
193213
})
194214
.collect::<Vec<ExpLoc>>()
195215
};

0 commit comments

Comments
 (0)