From 140c6a612e9d9b04966d03fa2b36fbe29d473a38 Mon Sep 17 00:00:00 2001 From: HolonProduction Date: Sun, 13 Oct 2024 19:01:30 +0200 Subject: [PATCH] GDScript: Fix annotation parsing adding new annotation entries --- modules/gdscript/gdscript_parser.cpp | 16 +++++++++------- .../parser/errors/annotation_inapplicable.gd | 3 +++ .../parser/errors/annotation_inapplicable.out | 2 ++ .../parser/errors/annotation_unrecognized.gd | 3 +++ .../parser/errors/annotation_unrecognized.out | 2 ++ 5 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 modules/gdscript/tests/scripts/parser/errors/annotation_inapplicable.gd create mode 100644 modules/gdscript/tests/scripts/parser/errors/annotation_inapplicable.out create mode 100644 modules/gdscript/tests/scripts/parser/errors/annotation_unrecognized.gd create mode 100644 modules/gdscript/tests/scripts/parser/errors/annotation_unrecognized.out diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 111a39d7302..e30f03afad1 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -1624,15 +1624,17 @@ GDScriptParser::AnnotationNode *GDScriptParser::parse_annotation(uint32_t p_vali valid = false; } - annotation->info = &valid_annotations[annotation->name]; + if (valid) { + annotation->info = &valid_annotations[annotation->name]; - if (!annotation->applies_to(p_valid_targets)) { - if (annotation->applies_to(AnnotationInfo::SCRIPT)) { - push_error(vformat(R"(Annotation "%s" must be at the top of the script, before "extends" and "class_name".)", annotation->name)); - } else { - push_error(vformat(R"(Annotation "%s" is not allowed in this level.)", annotation->name)); + if (!annotation->applies_to(p_valid_targets)) { + if (annotation->applies_to(AnnotationInfo::SCRIPT)) { + push_error(vformat(R"(Annotation "%s" must be at the top of the script, before "extends" and "class_name".)", annotation->name)); + } else { + push_error(vformat(R"(Annotation "%s" is not allowed in this level.)", annotation->name)); + } + valid = false; } - valid = false; } if (check(GDScriptTokenizer::Token::PARENTHESIS_OPEN)) { diff --git a/modules/gdscript/tests/scripts/parser/errors/annotation_inapplicable.gd b/modules/gdscript/tests/scripts/parser/errors/annotation_inapplicable.gd new file mode 100644 index 00000000000..cfacb6a0104 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/annotation_inapplicable.gd @@ -0,0 +1,3 @@ +@export +func test(): + pass diff --git a/modules/gdscript/tests/scripts/parser/errors/annotation_inapplicable.out b/modules/gdscript/tests/scripts/parser/errors/annotation_inapplicable.out new file mode 100644 index 00000000000..ed677cd39a8 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/annotation_inapplicable.out @@ -0,0 +1,2 @@ +GDTEST_PARSER_ERROR +Annotation "@export" cannot be applied to a function. diff --git a/modules/gdscript/tests/scripts/parser/errors/annotation_unrecognized.gd b/modules/gdscript/tests/scripts/parser/errors/annotation_unrecognized.gd new file mode 100644 index 00000000000..a6b171a428f --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/annotation_unrecognized.gd @@ -0,0 +1,3 @@ +@hello_world +func test(): + pass diff --git a/modules/gdscript/tests/scripts/parser/errors/annotation_unrecognized.out b/modules/gdscript/tests/scripts/parser/errors/annotation_unrecognized.out new file mode 100644 index 00000000000..540e66f15b8 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/annotation_unrecognized.out @@ -0,0 +1,2 @@ +GDTEST_PARSER_ERROR +Unrecognized annotation: "@hello_world".