Skip to content

Commit

Permalink
fix: check infix expression is valid in program input
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Nov 5, 2024
1 parent 2247814 commit 205548b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion compiler/noirc_frontend/src/hir_def/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,6 @@ impl Type {
| Type::Forall(_, _)
| Type::Quoted(_)
| Type::Slice(_)
| Type::InfixExpr(_, _, _)
| Type::TraitAsType(..) => false,

Type::Alias(alias, generics) => {
Expand All @@ -1205,6 +1204,10 @@ impl Type {
.get_fields(generics)
.into_iter()
.all(|(_, field)| field.is_valid_for_program_input()),

Type::InfixExpr(lhs, _, rhs) => {
lhs.is_valid_for_program_input() && rhs.is_valid_for_program_input()
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions compiler/noirc_frontend/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3623,3 +3623,15 @@ fn use_type_alias_to_generic_concrete_type_in_method_call() {
"#;
assert_no_errors(src);
}

#[test]
fn allows_struct_with_generic_infix_type_as_main_input() {
let src = r#"
struct Foo<let N: u32> {
x: [u64; N * 2],
}
fn main(_x: Foo<18>) {}
"#;
assert_no_errors(src);
}

0 comments on commit 205548b

Please sign in to comment.