diff --git a/crates/aiken-lang/src/gen_uplc.rs b/crates/aiken-lang/src/gen_uplc.rs index dafad997..ba1323e5 100644 --- a/crates/aiken-lang/src/gen_uplc.rs +++ b/crates/aiken-lang/src/gen_uplc.rs @@ -45,7 +45,7 @@ use self::{ lookup_data_type_by_tipo, modify_cyclic_calls, modify_self_calls, rearrange_list_clauses, AssignmentProperties, ClauseProperties, CodeGenSpecialFuncs, CycleFunctionNames, DataTypeKey, FunctionAccessKey, HoistableFunction, Variant, CONSTR_NOT_EMPTY, - INCORRECT_BOOLEAN, INCORRECT_CONSTR, LIST_NOT_EMPTY, TOO_MANY_ITEMS, + INCORRECT_CONSTR, LIST_NOT_EMPTY, TOO_MANY_ITEMS, }, tree::{AirExpression, AirTree, TreePath}, }; @@ -1062,9 +1062,16 @@ impl<'a> CodeGenerator<'a> { sequence.push(constructor_val); + let msg = get_src_code_by_span( + &props.module_name, + &props.location, + &self.module_src, + ); + let assert_constr = AirTree::assert_constr_index( index, AirTree::local_var(&constructor_name, tipo.clone()), + msg, ); sequence.push(assert_constr); @@ -4442,15 +4449,13 @@ impl<'a> CodeGenerator<'a> { arg_stack.push(term); } - Air::AssertConstr { constr_index } => { + Air::AssertConstr { constr_index, msg } => { let constr = arg_stack.pop().unwrap(); let mut term = arg_stack.pop().unwrap(); let trace_term = if self.tracing { - Term::Error.delayed_trace(Term::var( - self.special_functions.use_function(INCORRECT_CONSTR), - )) + Term::Error.delayed_trace(Term::string(msg)) } else { Term::Error }; diff --git a/crates/aiken-lang/src/gen_uplc/air.rs b/crates/aiken-lang/src/gen_uplc/air.rs index 76d5ec30..e507cb3a 100644 --- a/crates/aiken-lang/src/gen_uplc/air.rs +++ b/crates/aiken-lang/src/gen_uplc/air.rs @@ -89,6 +89,7 @@ pub enum Air { }, AssertConstr { constr_index: usize, + msg: String, }, AssertBool { is_true: bool, diff --git a/crates/aiken-lang/src/gen_uplc/tree.rs b/crates/aiken-lang/src/gen_uplc/tree.rs index f5c541bc..9e13925d 100644 --- a/crates/aiken-lang/src/gen_uplc/tree.rs +++ b/crates/aiken-lang/src/gen_uplc/tree.rs @@ -127,6 +127,7 @@ pub enum AirStatement { AssertConstr { constr_index: usize, constr: Box, + msg: String, }, AssertBool { is_true: bool, @@ -493,11 +494,12 @@ impl AirTree { value: value.into(), }) } - pub fn assert_constr_index(constr_index: usize, constr: AirTree) -> AirTree { + pub fn assert_constr_index(constr_index: usize, constr: AirTree, msg: String) -> AirTree { AirTree::Statement { statement: AirStatement::AssertConstr { constr_index, constr: constr.into(), + msg, }, hoisted_over: None, } @@ -946,9 +948,11 @@ impl AirTree { AirStatement::AssertConstr { constr, constr_index, + msg, } => { air_vec.push(Air::AssertConstr { constr_index: *constr_index, + msg: msg.clone(), }); constr.create_air_vec(air_vec); }