GDScript: Fix range() being treated as array when optimized out

The call of range() in a for loop is optimized to use int or vectors, to
avoid allocating an array, however the type was set as array still. With
the new typed VM this is an issue as the type mismatch the actual value,
resulting in wrong instructions to be selected.
This commit is contained in:
George Marques 2020-11-25 11:35:07 -03:00
parent 60fd7bfe42
commit fb3dc2670a
No known key found for this signature in database
GPG key ID: 046BD46A3201E43D

View file

@ -978,7 +978,7 @@ void GDScriptAnalyzer::resolve_for(GDScriptParser::ForNode *p_for) {
if (!call->arguments[i]->is_constant) {
all_is_constant = false;
} else {
} else if (all_is_constant) {
args.write[i] = call->arguments[i]->reduced_value;
}
@ -1011,6 +1011,9 @@ void GDScriptAnalyzer::resolve_for(GDScriptParser::ForNode *p_for) {
}
}
if (p_for->list->is_constant) {
p_for->list->set_datatype(type_from_variant(p_for->list->reduced_value, p_for->list));
} else {
GDScriptParser::DataType list_type;
list_type.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT;
list_type.kind = GDScriptParser::DataType::BUILTIN;
@ -1019,6 +1022,7 @@ void GDScriptAnalyzer::resolve_for(GDScriptParser::ForNode *p_for) {
}
}
}
}
if (!list_resolved) {
resolve_node(p_for->list);