Skip to content

Commit

Permalink
Call function aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
jfecher committed Jan 30, 2025
1 parent 6d319af commit 18e51f2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/noirc_frontend/src/elaborator/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ impl<'context> Elaborator<'context> {

fn elaborate_call(&mut self, call: CallExpression, span: Span) -> (HirExpression, Type) {
let (func, func_type) = self.elaborate_expression(*call.func);
let func_type = func_type.follow_bindings();
let func_arg_types =
if let Type::Function(args, _, _, _) = &func_type { Some(args) } else { None };

Expand Down
16 changes: 16 additions & 0 deletions compiler/noirc_frontend/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4178,3 +4178,19 @@ fn errors_on_loop_without_break_with_nested_loop() {
CompilationError::ResolverError(ResolverError::LoopWithoutBreak { .. })
));
}

#[test]
fn call_function_alias_type() {
let src = r#"
type Alias<Env> = fn[Env](Field) -> Field;
fn main() {
call_fn(|x| x + 1);
}
fn call_fn<Env>(f: Alias<Env>) {
assert_eq(f(0), 1);
}
"#;
assert_no_errors(src);
}

0 comments on commit 18e51f2

Please sign in to comment.