diff options
author | Lunatoid <lunatoid@pm.me> | 2020-08-25 21:00:56 +0200 |
---|---|---|
committer | Lunatoid <lunatoid@pm.me> | 2020-09-02 00:11:58 +0200 |
commit | 07053d0c6a69e87825bbd3259ea268dd9f03e708 (patch) | |
tree | 206e2c56818d1c49bf682b64d177318921c6bccf /modules | |
parent | d70a17d5d37fd09b43882e7972f2ed93eb56b897 (diff) |
Fixed ParseError when calling Object.new()
Fixes #41462 where calling Object.new() in GDScript gave an error.
I fixed it by adding exclusion when checking if the name is a builtin
type to exclude objects with a comment detailing why.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gdscript/gdscript_analyzer.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 788b3c87ab..9c148e2148 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -2276,10 +2276,12 @@ void GDScriptAnalyzer::reduce_identifier(GDScriptParser::IdentifierNode *p_ident StringName name = p_identifier->name; p_identifier->source = GDScriptParser::IdentifierNode::UNDEFINED_SOURCE; - // Check globals. - if (GDScriptParser::get_builtin_type(name) < Variant::VARIANT_MAX) { + // Check globals. We make an exception for Variant::OBJECT because it's the base class for + // non-builtin types so we allow doing e.g. Object.new() + Variant::Type builtin_type = GDScriptParser::get_builtin_type(name); + if (builtin_type != Variant::OBJECT && builtin_type < Variant::VARIANT_MAX) { if (can_be_builtin) { - p_identifier->set_datatype(make_builtin_meta_type(GDScriptParser::get_builtin_type(name))); + p_identifier->set_datatype(make_builtin_meta_type(builtin_type)); return; } else { push_error(R"(Builtin type cannot be used as a name on its own.)", p_identifier); |