GDScript: Don't allow builtin type names as identifiers

This commit is contained in:
George Marques 2021-09-29 11:23:16 -03:00
parent 5e609d0e8c
commit 72c07708e8
No known key found for this signature in database
GPG key ID: 046BD46A3201E43D
9 changed files with 30 additions and 0 deletions

View file

@ -175,6 +175,11 @@ Error GDScriptAnalyzer::check_native_member_name_conflict(const StringName &p_me
return ERR_PARSE_ERROR;
}
if (GDScriptParser::get_builtin_type(p_member_name) != Variant::VARIANT_MAX) {
push_error(vformat(R"(The member "%s" cannot have the same name as a builtin type.)", p_member_name), p_member_node);
return ERR_PARSE_ERROR;
}
return OK;
}

View file

@ -0,0 +1,5 @@
class Vector2:
pass
func test():
pass

View file

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
The member "Vector2" cannot have the same name as a builtin type.

View file

@ -0,0 +1,4 @@
const Vector2 = 0
func test():
pass

View file

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
The member "Vector2" cannot have the same name as a builtin type.

View file

@ -0,0 +1,4 @@
enum Vector2 { A, B }
func test():
pass

View file

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
The member "Vector2" cannot have the same name as a builtin type.

View file

@ -0,0 +1,4 @@
var Vector2
func test():
pass

View file

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
The member "Vector2" cannot have the same name as a builtin type.