From c07b49280aee24b07e0da7fd42dee4cba187cf13 Mon Sep 17 00:00:00 2001 From: lupoDharkael Date: Sat, 13 Apr 2019 17:26:58 +0200 Subject: [PATCH] Prevent using multiple class_name in a class --- modules/gdscript/gdscript_parser.cpp | 8 +++++++- modules/gdscript/gdscript_parser.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 8a9eacd8354..3a9bed47d96 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -3372,7 +3372,7 @@ void GDScriptParser::_parse_extends(ClassNode *p_class) { return; } - if (!p_class->constant_expressions.empty() || !p_class->subclasses.empty() || !p_class->functions.empty() || !p_class->variables.empty()) { + if (!p_class->constant_expressions.empty() || !p_class->subclasses.empty() || !p_class->functions.empty() || !p_class->variables.empty() || p_class->classname_used) { _set_error("'extends' must be used before anything else."); return; @@ -3509,6 +3509,12 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { _set_error("'class_name' syntax: 'class_name '"); return; } + if (p_class->classname_used) { + _set_error("'class_name' already used for this class."); + return; + } + + p_class->classname_used = true; p_class->name = tokenizer->get_token_identifier(1); diff --git a/modules/gdscript/gdscript_parser.h b/modules/gdscript/gdscript_parser.h index 809bff8f200..5e4de113570 100644 --- a/modules/gdscript/gdscript_parser.h +++ b/modules/gdscript/gdscript_parser.h @@ -149,6 +149,7 @@ public: bool tool; StringName name; bool extends_used; + bool classname_used; StringName extends_file; Vector extends_class; DataType base_type; @@ -198,6 +199,7 @@ public: tool = false; type = TYPE_CLASS; extends_used = false; + classname_used = false; end_line = -1; owner = NULL; }