diff options
author | Yuri Sizov <11782833+YuriSizov@users.noreply.github.com> | 2023-04-14 13:21:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-14 13:21:54 +0200 |
commit | afca0b8fdd07ff2e50f421a0e5424897cff1eb77 (patch) | |
tree | 6a43bdb8db525c529d60ea888477a61e94f02d24 /modules/gdscript/gdscript_analyzer.cpp | |
parent | bd3286eed23718afc87e7a6013aa88639f1d3da1 (diff) | |
parent | 66279b98b6c3418232003cc8d6c2e52af7a62ac4 (diff) | |
download | redot-engine-afca0b8fdd07ff2e50f421a0e5424897cff1eb77.tar.gz |
Merge pull request #75879 from dalexeev/gds-fix-extends-crash
GDScript: Add missing member type check when resolving `extends`
Diffstat (limited to 'modules/gdscript/gdscript_analyzer.cpp')
-rw-r--r-- | modules/gdscript/gdscript_analyzer.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index a2cab25ce8..34535887af 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -479,7 +479,24 @@ Error GDScriptAnalyzer::resolve_class_inheritance(GDScriptParser::ClassNode *p_c } if (look_class->has_member(name)) { resolve_class_member(look_class, name, id); - base = look_class->get_member(name).get_datatype(); + GDScriptParser::ClassNode::Member member = look_class->get_member(name); + GDScriptParser::DataType member_datatype = member.get_datatype(); + + switch (member.type) { + case GDScriptParser::ClassNode::Member::CLASS: + break; // OK. + case GDScriptParser::ClassNode::Member::CONSTANT: + if (member_datatype.kind != GDScriptParser::DataType::SCRIPT && member_datatype.kind != GDScriptParser::DataType::CLASS) { + push_error(vformat(R"(Constant "%s" is not a preloaded script or class.)", name), id); + return ERR_PARSE_ERROR; + } + break; + default: + push_error(vformat(R"(Cannot use %s "%s" in extends chain.)", member.get_type_name(), name), id); + return ERR_PARSE_ERROR; + } + + base = member_datatype; found = true; break; } @@ -506,6 +523,9 @@ Error GDScriptAnalyzer::resolve_class_inheritance(GDScriptParser::ClassNode *p_c if (!id_type.is_set()) { push_error(vformat(R"(Could not find nested type "%s".)", id->name), id); return ERR_PARSE_ERROR; + } else if (id_type.kind != GDScriptParser::DataType::SCRIPT && id_type.kind != GDScriptParser::DataType::CLASS) { + push_error(vformat(R"(Identifier "%s" is not a preloaded script or class.)", id->name), id); + return ERR_PARSE_ERROR; } base = id_type; |