浏览代码

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.
George Marques 4 年之前
父节点
当前提交
fb3dc2670a
共有 1 个文件被更改,包括 10 次插入6 次删除
  1. 10 6
      modules/gdscript/gdscript_analyzer.cpp

+ 10 - 6
modules/gdscript/gdscript_analyzer.cpp

@@ -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,11 +1011,15 @@ void GDScriptAnalyzer::resolve_for(GDScriptParser::ForNode *p_for) {
 					}
 				}
 
-				GDScriptParser::DataType list_type;
-				list_type.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT;
-				list_type.kind = GDScriptParser::DataType::BUILTIN;
-				list_type.builtin_type = Variant::ARRAY;
-				p_for->list->set_datatype(list_type);
+				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;
+					list_type.builtin_type = Variant::ARRAY;
+					p_for->list->set_datatype(list_type);
+				}
 			}
 		}
 	}