diff options
author | Dmitrii Maganov <vonagam@gmail.com> | 2023-02-23 03:25:26 +0200 |
---|---|---|
committer | Dmitrii Maganov <vonagam@gmail.com> | 2023-02-23 10:38:53 +0200 |
commit | 7ee011051ace34a5d2091ceda9b3e178283824a2 (patch) | |
tree | 3e0e6c5ed2228f1a2b45665c88f53e8ba299df32 /modules/gdscript/gdscript_analyzer.cpp | |
parent | 19c9fd6926b958016d562e3b2e93b0e9480300f5 (diff) | |
download | redot-engine-7ee011051ace34a5d2091ceda9b3e178283824a2.tar.gz |
GDScript: Fix usage of enum value as range argument
Diffstat (limited to 'modules/gdscript/gdscript_analyzer.cpp')
-rw-r--r-- | modules/gdscript/gdscript_analyzer.cpp | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 5ce01a08bf..1161403c0c 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -1861,24 +1861,20 @@ void GDScriptAnalyzer::resolve_for(GDScriptParser::ForNode *p_for) { Vector<Variant> args; args.resize(call->arguments.size()); for (int i = 0; i < call->arguments.size(); i++) { - reduce_expression(call->arguments[i]); + GDScriptParser::ExpressionNode *argument = call->arguments[i]; + reduce_expression(argument); - if (!call->arguments[i]->is_constant) { + if (!argument->is_constant) { all_is_constant = false; - } else if (all_is_constant) { - args.write[i] = call->arguments[i]->reduced_value; + break; } - - GDScriptParser::DataType arg_type = call->arguments[i]->get_datatype(); - if (!arg_type.is_variant()) { - if (arg_type.kind != GDScriptParser::DataType::BUILTIN) { - all_is_constant = false; - push_error(vformat(R"*(Invalid argument for "range()" call. Argument %d should be int or float but "%s" was given.)*", i + 1, arg_type.to_string()), call->arguments[i]); - } else if (arg_type.builtin_type != Variant::INT && arg_type.builtin_type != Variant::FLOAT) { - all_is_constant = false; - push_error(vformat(R"*(Invalid argument for "range()" call. Argument %d should be int or float but "%s" was given.)*", i + 1, arg_type.to_string()), call->arguments[i]); - } + if (argument->reduced_value.get_type() != Variant::INT && argument->reduced_value.get_type() != Variant::FLOAT) { + push_error(vformat(R"*(Invalid argument for "range()" call. Argument %d should be int or float but "%s" was given.)*", i + 1, Variant::get_type_name(argument->reduced_value.get_type())), argument); + all_is_constant = false; + break; } + + args.write[i] = argument->reduced_value; } Variant reduced; |