Merge pull request #98146 from HolonProduction/this-error-does-not-apply-to-unrecognized-annotations

GDScript: Fix annotation parsing adding new annotation entries
This commit is contained in:
Thaddeus Crews 2024-10-21 16:39:24 -05:00
commit 55aeff19dc
No known key found for this signature in database
GPG Key ID: 62181B86FE9E5D84
5 changed files with 19 additions and 7 deletions

View File

@ -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)) {

View File

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

View File

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

View File

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

View File

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