Skip to content

Commit

Permalink
[Compiler-v2][trivial] fix error handling for match in expansion ph…
Browse files Browse the repository at this point in the history
…ase (#15173)

* fix

* add error only when there isn't one
  • Loading branch information
rahxephon89 authored Nov 4, 2024
1 parent 9baf39b commit 5fbf9b7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

Diagnostics:
error: unbound module
┌─ tests/checking/variants/bug_15073.move:8:13
8 │ ToolType::Http { uri } => {
│ ^^^^^^^^ Unbound module or type alias 'ToolType'
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module 0x815::m {

public fun init_registration(
creator: &signer,
tool_type: ToolType
) {
match(tool_type) {
ToolType::Http { uri } => {

},
}

}
}
19 changes: 14 additions & 5 deletions third_party/move/move-compiler/src/expansion/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2600,13 +2600,22 @@ fn exp_(context: &mut Context, sp!(loc, pe_): P::Exp) -> E::Exp {
let discriminator = exp(context, *pd);
let match_arms = parms
.into_iter()
.map(|parm| {
.filter_map(|parm| {
let loc = parm.loc;
let (pbl, pc, pb) = parm.value;
let bind_list = bind_list(context, pbl).expect("bind list always present");
let opt_cond = pc.map(|e| *exp(context, e));
let body = *exp(context, pb);
sp(loc, (bind_list, opt_cond, body))
if let Some(bind_list) = bind_list(context, pbl) {
let opt_cond = pc.map(|e| *exp(context, e));
let body = *exp(context, pb);
Some(sp(loc, (bind_list, opt_cond, body)))
} else {
if !context.env.has_errors() {
context.env.add_diag(diag!(
Syntax::InvalidLValue,
(loc, "bind list cannot be constructed")
));
}
None
}
})
.collect::<Vec<_>>();
EE::Match(discriminator, match_arms)
Expand Down

0 comments on commit 5fbf9b7

Please sign in to comment.