Browse Source

Merge pull request #53216 from vnen/gdscript-builtin-type-not-id

Rémi Verschelde 3 năm trước cách đây
mục cha
commit
27d4e2f09f

+ 5 - 0
modules/gdscript/gdscript_analyzer.cpp

@@ -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;
 }
 

+ 5 - 0
modules/gdscript/tests/scripts/analyzer/errors/class_name_shadows_builtin_type.gd

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

+ 2 - 0
modules/gdscript/tests/scripts/analyzer/errors/class_name_shadows_builtin_type.out

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

+ 4 - 0
modules/gdscript/tests/scripts/analyzer/errors/constant_name_shadows_builtin_type.gd

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

+ 2 - 0
modules/gdscript/tests/scripts/analyzer/errors/constant_name_shadows_builtin_type.out

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

+ 4 - 0
modules/gdscript/tests/scripts/analyzer/errors/enum_name_shadows_builtin_type.gd

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

+ 2 - 0
modules/gdscript/tests/scripts/analyzer/errors/enum_name_shadows_builtin_type.out

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

+ 4 - 0
modules/gdscript/tests/scripts/analyzer/errors/variable_name_shadows_builtin_type.gd

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

+ 2 - 0
modules/gdscript/tests/scripts/analyzer/errors/variable_name_shadows_builtin_type.out

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