Skip to content

Commit de3e77a

Browse files
authored
fix: use correct type for attribute arguments (#6640)
1 parent 59c0c35 commit de3e77a

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

compiler/noirc_frontend/src/elaborator/comptime.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,15 +329,14 @@ impl<'context> Elaborator<'context> {
329329
push_arg(Value::TraitDefinition(trait_id));
330330
} else {
331331
let (expr_id, expr_type) = interpreter.elaborator.elaborate_expression(arg);
332-
push_arg(interpreter.evaluate(expr_id)?);
333-
334332
if let Err(UnificationError) = expr_type.unify(param_type) {
335333
return Err(InterpreterError::TypeMismatch {
336334
expected: param_type.clone(),
337335
actual: expr_type,
338336
location: arg_location,
339337
});
340338
}
339+
push_arg(interpreter.evaluate(expr_id)?);
341340
};
342341
}
343342

compiler/noirc_frontend/src/tests/metaprogramming.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,23 @@ fn errors_if_macros_inject_functions_with_name_collisions() {
141141
) if contents == "foo"
142142
));
143143
}
144+
145+
#[test]
146+
fn uses_correct_type_for_attribute_arguments() {
147+
let src = r#"
148+
#[foo(32)]
149+
comptime fn foo(_f: FunctionDefinition, i: u32) {
150+
let y: u32 = 1;
151+
let _ = y == i;
152+
}
153+
154+
#[bar([0; 2])]
155+
comptime fn bar(_f: FunctionDefinition, i: [u32; 2]) {
156+
let y: u32 = 1;
157+
let _ = y == i[0];
158+
}
159+
160+
fn main() {}
161+
"#;
162+
assert_no_errors(src);
163+
}

0 commit comments

Comments
 (0)