Преглед изворни кода

GDScript: Fix annotation parsing adding new annotation entries

HolonProduction пре 11 месеци
родитељ
комит
140c6a612e

+ 9 - 7
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)) {

+ 3 - 0
modules/gdscript/tests/scripts/parser/errors/annotation_inapplicable.gd

@@ -0,0 +1,3 @@
+@export
+func test():
+    pass

+ 2 - 0
modules/gdscript/tests/scripts/parser/errors/annotation_inapplicable.out

@@ -0,0 +1,2 @@
+GDTEST_PARSER_ERROR
+Annotation "@export" cannot be applied to a function.

+ 3 - 0
modules/gdscript/tests/scripts/parser/errors/annotation_unrecognized.gd

@@ -0,0 +1,3 @@
+@hello_world
+func test():
+    pass

+ 2 - 0
modules/gdscript/tests/scripts/parser/errors/annotation_unrecognized.out

@@ -0,0 +1,2 @@
+GDTEST_PARSER_ERROR
+Unrecognized annotation: "@hello_world".