re-introduce code-gen patch, but with a test.

Actually, this has been a bug for a long time it seems. Calling any
  prelude functions using a qualified import would result in a codegen
  crash. Whoopsie.

  This is now fixed as shown by the regression test.
This commit is contained in:
KtorZ 2024-07-19 09:40:05 +02:00
parent 5afcc9b0c1
commit a9d782e206
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
2 changed files with 36 additions and 2 deletions

View File

@ -17,7 +17,7 @@ use crate::{
Span, TraceLevel, Tracing, TypedArg, TypedClause, TypedDataType, TypedFunction, Span, TraceLevel, Tracing, TypedArg, TypedClause, TypedDataType, TypedFunction,
TypedPattern, TypedValidator, UnOp, TypedPattern, TypedValidator, UnOp,
}, },
builtins::{bool, data, int, list, void}, builtins::{bool, data, int, list, void, PRELUDE},
expr::TypedExpr, expr::TypedExpr,
gen_uplc::{ gen_uplc::{
air::ExpectLevel, air::ExpectLevel,
@ -748,7 +748,19 @@ impl<'a> CodeGenerator<'a> {
} }
ModuleValueConstructor::Fn { name, module, .. } => { ModuleValueConstructor::Fn { name, module, .. } => {
let func = self.functions.get(&FunctionAccessKey { let func = self.functions.get(&FunctionAccessKey {
module_name: module_name.clone(), // NOTE: This is needed because we register prelude functions under an
// empty module name. This is to facilitate their access when used
// directly. Note that, if we weren't doing this particular
// transformation, we would need to do the other direction anyway:
//
// if module_name.is_empty() { PRELUDE.to_string() } else { module_name.clone() }
//
// So either way, we need to take care of this.
module_name: if module_name == PRELUDE {
String::new()
} else {
module_name.clone()
},
function_name: name.clone(), function_name: name.clone(),
}); });

View File

@ -7003,3 +7003,25 @@ fn bls12_381_elements_from_data_conversion() {
false, false,
) )
} }
#[test]
fn qualified_prelude_functions() {
let src = r#"
use aiken
test foo() {
aiken.identity(True) && identity(True)
}
"#;
let constant_true = Term::Constant(Constant::Bool(true).into());
let constant_false = Term::Constant(Constant::Bool(false).into());
assert_uplc(
src,
constant_true
.clone()
.delayed_if_then_else(constant_true, constant_false),
false,
)
}