summaryrefslogtreecommitdiff
path: root/modules/gdscript
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2019-09-03 20:23:27 +0200
committerMitch Curtis <mitch.curtis@qt.io>2019-09-06 17:12:43 +0200
commit8f5ffeeacc3ee5537f32a931f2d1ad566747ad9f (patch)
tree0057c238c611be2aa34cfcdd9c4ac3e26b76ef13 /modules/gdscript
parent750f8d4926edb14269d9f6a117c5a9fd4765373a (diff)
Produce an error when a class has the same name as a Singleton
If you somehow end up with a Singleton.gd that looks like this: extends Node class_name Singleton func foo(): pass You will get an error when using it in another file: extends Node2D func _init(): # Parser Error: Non-static function "foo" can only be called from an instance. Singleton.foo() This error is confusing. This patch ensures that an error on the class_name line will be produced: Parse Error: The class "Singleton" conflicts with the AutoLoad singleton of the same name, and is therefore redundant. Remove the class_name declaration to fix this error. Fixes #28187.
Diffstat (limited to 'modules/gdscript')
-rw-r--r--modules/gdscript/gdscript_parser.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp
index e96bf0238a..71cb44b196 100644
--- a/modules/gdscript/gdscript_parser.cpp
+++ b/modules/gdscript/gdscript_parser.cpp
@@ -3533,6 +3533,15 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
return;
}
+ if (p_class->classname_used && ProjectSettings::get_singleton()->has_setting("autoload/" + p_class->name)) {
+ const String autoload_path = ProjectSettings::get_singleton()->get_setting("autoload/" + p_class->name);
+ if (autoload_path.begins_with("*")) {
+ // It's a singleton, and not just a regular AutoLoad script.
+ _set_error("The class \"" + p_class->name + "\" conflicts with the AutoLoad singleton of the same name, and is therefore redundant. Remove the class_name declaration to fix this error.");
+ }
+ return;
+ }
+
tokenizer->advance(2);
if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) {