Skip to content

Commit

Permalink
fix: Avoid type error when calling something with a type alias of a f…
Browse files Browse the repository at this point in the history
…unction (#7239)
  • Loading branch information
jfecher authored Jan 30, 2025
1 parent 6d319af commit 429ae52
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);
}

2 comments on commit 429ae52

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Test Suite Duration'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: 429ae52 Previous: 6d319af Ratio
noir-lang_noir_check_shuffle_ 1 s 0 s +∞
noir-lang_noir_base64_ 2 s 1 s 2
noir-lang_mimc_ 1 s 0 s +∞
AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_parity-lib 4 s 3 s 1.33

This comment was automatically generated by workflow using github-action-benchmark.

CC: @TomAFrench

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Test Suite Duration'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: 429ae52 Previous: 6d319af Ratio
noir-lang_noir_sort_ 1 s 0 s +∞
noir-lang_noir_base64_ 2 s 1 s 2

This comment was automatically generated by workflow using github-action-benchmark.

CC: @TomAFrench

Please sign in to comment.