diff --git a/test_programs/compile_success_empty/lambda_call_assign_in_lambda/Nargo.toml b/test_programs/compile_success_empty/lambda_call_assign_in_lambda/Nargo.toml new file mode 100644 index 00000000000..9579afe99ea --- /dev/null +++ b/test_programs/compile_success_empty/lambda_call_assign_in_lambda/Nargo.toml @@ -0,0 +1,6 @@ +[package] +name = "lambda_call_assign_in_lambda" +type = "bin" +authors = [""] + +[dependencies] \ No newline at end of file diff --git a/test_programs/compile_success_empty/lambda_call_assign_in_lambda/src/main.nr b/test_programs/compile_success_empty/lambda_call_assign_in_lambda/src/main.nr new file mode 100644 index 00000000000..7999d1445bc --- /dev/null +++ b/test_programs/compile_success_empty/lambda_call_assign_in_lambda/src/main.nr @@ -0,0 +1,23 @@ +// Regression for issue #5212 (https://github.com/noir-lang/noir/issues/5212) +fn main() { + let lambda1 = || 1; + + // Previous bug: Compiler panic when you create a variable in a lambda with another lambda call as its value + let _ = || { let _: u8 = lambda1(); }; + + // No panic if the variable is created before we assign its value as the lambda call + let _ = || { + let mut var3: u8 = 1; + var3 = lambda1(); + }; + + // No panic with a function call that has the same behavior + let _ = || { let _: u8 = func(); }; + + // No panic outside a lambda code block + let _: u8 = lambda1(); +} + +fn func() -> u8 { + 1 +} diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/lambda_call_assign_in_lambda/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/lambda_call_assign_in_lambda/execute__tests__expanded.snap new file mode 100644 index 00000000000..b01a00e6b7b --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/lambda_call_assign_in_lambda/execute__tests__expanded.snap @@ -0,0 +1,18 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: expanded_code +--- +fn main() { + let lambda1: fn() -> u8 = || -> u8 1; + let _: fn[(fn() -> u8,)]() = || { let _: u8 = lambda1(); }; + let _: fn[(fn() -> u8,)]() = || { + let mut var3: u8 = 1; + var3 = lambda1(); + }; + let _: fn() = || { let _: u8 = func(); }; + let _: u8 = lambda1(); +} + +fn func() -> u8 { + 1 +} diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/lambda_call_assign_in_lambda/execute__tests__force_brillig_false_inliner_0.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/lambda_call_assign_in_lambda/execute__tests__force_brillig_false_inliner_0.snap new file mode 100644 index 00000000000..7de940827c8 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/lambda_call_assign_in_lambda/execute__tests__force_brillig_false_inliner_0.snap @@ -0,0 +1,26 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [], + "return_type": null, + "error_types": {} + }, + "bytecode": [ + "func 0", + "current witness index : _0", + "private parameters indices : []", + "public parameters indices : []", + "return value indices : []" + ], + "debug_symbols": "XY5BCsQwCEXv4rqLWfcqw1BsaosgJtikMITefWyYQOlK/3/6tcJCc9km1jXuML4rzMYivE0SA2aO6m49B+hyykbkFty4byU00gyjFpEBDpTShvaE2mpGc/oagHTx6oErC13d+XGBge158UBjnIX+ci0abjR/Uyf942Qx0FKMrqTGPPsH", + "file_map": {}, + "names": [ + "main" + ], + "brillig_names": [] +}