Skip to content

Commit

Permalink
fix: use correct type for attribute arguments (#6640)
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite authored Dec 2, 2024
1 parent 59c0c35 commit de3e77a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 1 addition & 2 deletions compiler/noirc_frontend/src/elaborator/comptime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,14 @@ impl<'context> Elaborator<'context> {
push_arg(Value::TraitDefinition(trait_id));
} else {
let (expr_id, expr_type) = interpreter.elaborator.elaborate_expression(arg);
push_arg(interpreter.evaluate(expr_id)?);

if let Err(UnificationError) = expr_type.unify(param_type) {
return Err(InterpreterError::TypeMismatch {
expected: param_type.clone(),
actual: expr_type,
location: arg_location,
});
}
push_arg(interpreter.evaluate(expr_id)?);
};
}

Expand Down
20 changes: 20 additions & 0 deletions compiler/noirc_frontend/src/tests/metaprogramming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,23 @@ fn errors_if_macros_inject_functions_with_name_collisions() {
) if contents == "foo"
));
}

#[test]
fn uses_correct_type_for_attribute_arguments() {
let src = r#"
#[foo(32)]
comptime fn foo(_f: FunctionDefinition, i: u32) {
let y: u32 = 1;
let _ = y == i;
}
#[bar([0; 2])]
comptime fn bar(_f: FunctionDefinition, i: [u32; 2]) {
let y: u32 = 1;
let _ = y == i[0];
}
fn main() {}
"#;
assert_no_errors(src);
}

0 comments on commit de3e77a

Please sign in to comment.