From 18e51f298a64126b8a57257b3559f5b9581987f9 Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Thu, 30 Jan 2025 09:25:24 -0600 Subject: [PATCH] Call function aliases --- .../noirc_frontend/src/elaborator/expressions.rs | 1 + compiler/noirc_frontend/src/tests.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/compiler/noirc_frontend/src/elaborator/expressions.rs b/compiler/noirc_frontend/src/elaborator/expressions.rs index c76fee835e7..ff5ff48cbf4 100644 --- a/compiler/noirc_frontend/src/elaborator/expressions.rs +++ b/compiler/noirc_frontend/src/elaborator/expressions.rs @@ -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 }; diff --git a/compiler/noirc_frontend/src/tests.rs b/compiler/noirc_frontend/src/tests.rs index 6acb3b4b59e..b7723ce4242 100644 --- a/compiler/noirc_frontend/src/tests.rs +++ b/compiler/noirc_frontend/src/tests.rs @@ -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 = fn[Env](Field) -> Field; + + fn main() { + call_fn(|x| x + 1); + } + + fn call_fn(f: Alias) { + assert_eq(f(0), 1); + } + "#; + assert_no_errors(src); +}