diff options
-rw-r--r-- | modules/gdscript/gdscript_compiler.cpp | 25 | ||||
-rw-r--r-- | modules/gdscript/gdscript_parser.cpp | 35 |
2 files changed, 51 insertions, 9 deletions
diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index 3121a61436..4cd6472b7f 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -1686,21 +1686,44 @@ Error GDScriptCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, cons base_class = p->subclasses[base]; break; } + + if (p->constants.has(base)) { + + base_class = p->constants[base]; + if (base_class.is_null()) { + _set_error("Constant is not a class: " + base, p_class); + return ERR_SCRIPT_FAILED; + } + break; + } + p = p->_owner; } if (base_class.is_valid()) { + String ident = base; + for (int i = 1; i < p_class->extends_class.size(); i++) { String subclass = p_class->extends_class[i]; + ident += ("." + subclass); + if (base_class->subclasses.has(subclass)) { base_class = base_class->subclasses[subclass]; + } else if (base_class->constants.has(subclass)) { + + Ref<GDScript> new_base_class = base_class->constants[subclass]; + if (new_base_class.is_null()) { + _set_error("Constant is not a class: " + ident, p_class); + return ERR_SCRIPT_FAILED; + } + base_class = new_base_class; } else { - _set_error("Could not find subclass: " + subclass, p_class); + _set_error("Could not find subclass: " + ident, p_class); return ERR_FILE_NOT_FOUND; } } diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 1e677f11c4..bee9ef1998 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -2971,18 +2971,37 @@ void GDScriptParser::_parse_extends(ClassNode *p_class) { } while (true) { - if (tokenizer->get_token() != GDScriptTokenizer::TK_IDENTIFIER) { - _set_error("Invalid 'extends' syntax, expected string constant (path) and/or identifier (parent class)."); - return; - } + switch (tokenizer->get_token()) { + + case GDScriptTokenizer::TK_IDENTIFIER: { + + StringName identifier = tokenizer->get_token_identifier(); + p_class->extends_class.push_back(identifier); + } + break; + + case GDScriptTokenizer::TK_PERIOD: + break; + + default: { - StringName identifier = tokenizer->get_token_identifier(); - p_class->extends_class.push_back(identifier); + _set_error("Invalid 'extends' syntax, expected string constant (path) and/or identifier (parent class)."); + return; + } + } tokenizer->advance(1); - if (tokenizer->get_token() != GDScriptTokenizer::TK_PERIOD) - return; + + switch (tokenizer->get_token()) { + + case GDScriptTokenizer::TK_IDENTIFIER: + case GDScriptTokenizer::TK_PERIOD: + continue; + + default: + return; + } } } |