diff --git a/compiler/ast/README.md b/compiler/ast/README.md index 0cb2f0f03d..85615b9c8b 100644 --- a/compiler/ast/README.md +++ b/compiler/ast/README.md @@ -33,7 +33,7 @@ Contains the Circuit's name, as well as its members. The members are a function, or a variable, or a constant. For all of them the Circuit preserves their names. -#### [Decorators](./src/functions/annotation.rs) +#### [Annotations](./src/functions/annotation.rs) An annotation node is a decorator that can be applied to a function. Stored on the function themselves despite being a top-level node. diff --git a/compiler/passes/src/code_generation/visit_program.rs b/compiler/passes/src/code_generation/visit_program.rs index e9f95dcef8..88d2d7d462 100644 --- a/compiler/passes/src/code_generation/visit_program.rs +++ b/compiler/passes/src/code_generation/visit_program.rs @@ -83,10 +83,10 @@ impl<'a> CodeGenerator<'a> { closures.push_str(&function_string); closures.push('\n'); } - }); - // Unset the `is_program_function` flag. - self.is_program_function = false; + // Unset the `is_program_function` flag. + self.is_program_function = false; + }); // Closures must precede functions in the Aleo program. program_string.push_str(&closures); @@ -187,9 +187,6 @@ impl<'a> CodeGenerator<'a> { let block_string = self.visit_block(&function.block); function_string.push_str(&block_string); - // Unset `is_program_function` after visiting `function`. - self.is_program_function = false; - function_string } } diff --git a/tests/expectations/parser/functions/danling_annotations_fail.out b/tests/expectations/parser/functions/danling_annotations_fail.out new file mode 100644 index 0000000000..d477814b4f --- /dev/null +++ b/tests/expectations/parser/functions/danling_annotations_fail.out @@ -0,0 +1,28 @@ +--- +namespace: Parse +expectation: Pass +outputs: + - name: "" + network: "" + expected_input: [] + imports: {} + functions: + "{\"name\":\"test\",\"span\":\"{\\\"lo\\\":94,\\\"hi\\\":98}\"}": + annotations: + - identifier: "{\"name\":\"test\",\"span\":\"{\\\"lo\\\":79,\\\"hi\\\":83}\"}" + span: + lo: 78 + hi: 83 + identifier: "{\"name\":\"test\",\"span\":\"{\\\"lo\\\":94,\\\"hi\\\":98}\"}" + input: [] + output: U8 + core_mapping: ~ + block: + statements: [] + span: + lo: 107 + hi: 109 + span: + lo: 85 + hi: 109 + circuits: {} diff --git a/tests/expectations/parser/functions/spaced_annotation_fail.out b/tests/expectations/parser/functions/spaced_annotation_fail.out new file mode 100644 index 0000000000..fc9be044a3 --- /dev/null +++ b/tests/expectations/parser/functions/spaced_annotation_fail.out @@ -0,0 +1,5 @@ +--- +namespace: Parse +expectation: Fail +outputs: + - "Error [EPAR0370028]: Illegal spacing in the annotation declaration.\n --> test:3:1\n |\n 3 | @ test\n | ^^^^^^\n |\n = Remove whitespace between the `@` symbol and the identifier." diff --git a/tests/parser/functions/annotated_functions_fail.leo b/tests/parser/functions/danling_annotations_fail.leo similarity index 100% rename from tests/parser/functions/annotated_functions_fail.leo rename to tests/parser/functions/danling_annotations_fail.leo diff --git a/tests/parser/functions/spaced_annotation_fail.leo b/tests/parser/functions/spaced_annotation_fail.leo new file mode 100644 index 0000000000..6e21099b54 --- /dev/null +++ b/tests/parser/functions/spaced_annotation_fail.leo @@ -0,0 +1,7 @@ +/* +namespace: Parse +expectation: Fail +*/ + +@ test +function test() -> u8 {}