From 5fbf9b72f2294d85e358b5882b290310a9f7482b Mon Sep 17 00:00:00 2001 From: Teng Zhang Date: Mon, 4 Nov 2024 19:37:38 +0000 Subject: [PATCH] [Compiler-v2][trivial] fix error handling for `match` in expansion phase (#15173) * fix * add error only when there isn't one --- .../tests/checking/variants/bug_15073.exp | 7 +++++++ .../tests/checking/variants/bug_15073.move | 14 ++++++++++++++ .../move-compiler/src/expansion/translate.rs | 19 ++++++++++++++----- 3 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 third_party/move/move-compiler-v2/tests/checking/variants/bug_15073.exp create mode 100644 third_party/move/move-compiler-v2/tests/checking/variants/bug_15073.move diff --git a/third_party/move/move-compiler-v2/tests/checking/variants/bug_15073.exp b/third_party/move/move-compiler-v2/tests/checking/variants/bug_15073.exp new file mode 100644 index 0000000000000..7abba59d663f5 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/checking/variants/bug_15073.exp @@ -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' diff --git a/third_party/move/move-compiler-v2/tests/checking/variants/bug_15073.move b/third_party/move/move-compiler-v2/tests/checking/variants/bug_15073.move new file mode 100644 index 0000000000000..da326a52c95a8 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/checking/variants/bug_15073.move @@ -0,0 +1,14 @@ +module 0x815::m { + + public fun init_registration( + creator: &signer, + tool_type: ToolType + ) { + match(tool_type) { + ToolType::Http { uri } => { + + }, + } + + } +} diff --git a/third_party/move/move-compiler/src/expansion/translate.rs b/third_party/move/move-compiler/src/expansion/translate.rs index ca954085198f3..b8ea685e454d7 100644 --- a/third_party/move/move-compiler/src/expansion/translate.rs +++ b/third_party/move/move-compiler/src/expansion/translate.rs @@ -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::>(); EE::Match(discriminator, match_arms)