From 2b4137dc2420e39660c25f7196416f0cfc65bf6b Mon Sep 17 00:00:00 2001 From: KtorZ Date: Fri, 19 Jan 2024 14:31:09 +0100 Subject: [PATCH] Revert "minor refactor" This reverts commit 21f0b3a6220fdafb8f6aad6855de89d8cdde0e1b. Rationale: The absence of clause guard was here done *on purpose*. Indeed, introducing a clause guard here forces either duplication or the use of a wildcard which is not "future proof". Should we make a change to that one day (e.g. add a new variant to TraceLevel), we won't get any compiler warning and we'll very likely forget to update that particular section of the code. So as much as possible, enforce complete pattern-match on variants make for code that is easier to maintain in the long-run. --- crates/aiken-lang/src/gen_uplc.rs | 44 ++++++++++++++++++------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/crates/aiken-lang/src/gen_uplc.rs b/crates/aiken-lang/src/gen_uplc.rs index 879d781a..3624a844 100644 --- a/crates/aiken-lang/src/gen_uplc.rs +++ b/crates/aiken-lang/src/gen_uplc.rs @@ -475,29 +475,35 @@ impl<'a> CodeGenerator<'a> { let air_value = self.build(value, module_name); let msg_func = match self.tracing { - TraceLevel::Verbose | TraceLevel::Compact if kind.is_expect() => { - let msg = match self.tracing { - TraceLevel::Silent => unreachable!("excluded from pattern guards"), - TraceLevel::Compact => { - get_line_columns_by_span(module_name, location, &self.module_src) - .to_string() - } - TraceLevel::Verbose => { - get_src_code_by_span(module_name, location, &self.module_src) - } - }; + TraceLevel::Silent => None, + TraceLevel::Verbose | TraceLevel::Compact => { + if kind.is_expect() { + let msg = match self.tracing { + TraceLevel::Silent => unreachable!("excluded from pattern guards"), + TraceLevel::Compact => get_line_columns_by_span( + module_name, + location, + &self.module_src, + ) + .to_string(), + TraceLevel::Verbose => { + get_src_code_by_span(module_name, location, &self.module_src) + } + }; - let msg_func_name = msg.split_whitespace().join(""); + let msg_func_name = msg.split_whitespace().join(""); - self.special_functions.insert_new_function( - msg_func_name.clone(), - Term::string(msg), - string(), - ); + self.special_functions.insert_new_function( + msg_func_name.clone(), + Term::string(msg), + string(), + ); - Some(self.special_functions.use_function_msg(msg_func_name)) + Some(self.special_functions.use_function_msg(msg_func_name)) + } else { + None + } } - _ => None, }; self.assignment(