| 2260 | } |
| 2261 | |
| 2262 | void GDScriptAnalyzer::resolve_for(GDScriptParser::ForNode *p_for) { |
| 2263 | GDScriptParser::DataType variable_type; |
| 2264 | GDScriptParser::DataType list_type; |
| 2265 | |
| 2266 | if (p_for->list) { |
| 2267 | resolve_node(p_for->list, false); |
| 2268 | |
| 2269 | bool is_range = false; |
| 2270 | if (p_for->list->type == GDScriptParser::Node::CALL) { |
| 2271 | GDScriptParser::CallNode *call = static_cast<GDScriptParser::CallNode *>(p_for->list); |
| 2272 | if (call->get_callee_type() == GDScriptParser::Node::IDENTIFIER) { |
| 2273 | if (static_cast<GDScriptParser::IdentifierNode *>(call->callee)->name == "range") { |
| 2274 | if (call->arguments.is_empty()) { |
| 2275 | push_error(R"*(Invalid call for "range()" function. Expected at least 1 argument, none given.)*", call); |
| 2276 | } else if (call->arguments.size() > 3) { |
| 2277 | push_error(vformat(R"*(Invalid call for "range()" function. Expected at most 3 arguments, %d given.)*", call->arguments.size()), call); |
| 2278 | } |
| 2279 | is_range = true; |
| 2280 | variable_type.type_source = GDScriptParser::DataType::ANNOTATED_INFERRED; |
| 2281 | variable_type.kind = GDScriptParser::DataType::BUILTIN; |
| 2282 | variable_type.builtin_type = Variant::INT; |
| 2283 | } |
| 2284 | } |
| 2285 | } |
| 2286 | |
| 2287 | list_type = p_for->list->get_datatype(); |
| 2288 | |
| 2289 | if (!list_type.is_hard_type()) { |
| 2290 | mark_node_unsafe(p_for->list); |
| 2291 | } |
| 2292 | |
| 2293 | if (is_range) { |
| 2294 | // Already solved. |
| 2295 | } else if (list_type.is_variant()) { |
| 2296 | variable_type.kind = GDScriptParser::DataType::VARIANT; |
| 2297 | mark_node_unsafe(p_for->list); |
| 2298 | } else if (list_type.has_container_element_type(0)) { |
| 2299 | variable_type = list_type.get_container_element_type(0); |
| 2300 | variable_type.type_source = list_type.type_source; |
| 2301 | } else if (list_type.is_typed_container_type()) { |
| 2302 | variable_type = list_type.get_typed_container_type(); |
| 2303 | variable_type.type_source = list_type.type_source; |
| 2304 | } else if (list_type.builtin_type == Variant::INT || list_type.builtin_type == Variant::FLOAT || list_type.builtin_type == Variant::STRING) { |
| 2305 | variable_type.type_source = list_type.type_source; |
| 2306 | variable_type.kind = GDScriptParser::DataType::BUILTIN; |
| 2307 | variable_type.builtin_type = list_type.builtin_type; |
| 2308 | } else if (list_type.builtin_type == Variant::VECTOR2I || list_type.builtin_type == Variant::VECTOR3I) { |
| 2309 | variable_type.type_source = list_type.type_source; |
| 2310 | variable_type.kind = GDScriptParser::DataType::BUILTIN; |
| 2311 | variable_type.builtin_type = Variant::INT; |
| 2312 | } else if (list_type.builtin_type == Variant::VECTOR2 || list_type.builtin_type == Variant::VECTOR3) { |
| 2313 | variable_type.type_source = list_type.type_source; |
| 2314 | variable_type.kind = GDScriptParser::DataType::BUILTIN; |
| 2315 | variable_type.builtin_type = Variant::FLOAT; |
| 2316 | } else if (list_type.builtin_type == Variant::OBJECT) { |
| 2317 | GDScriptParser::DataType return_type; |
| 2318 | List<GDScriptParser::DataType> par_types; |
| 2319 | int default_arg_count = 0; |
nothing calls this directly
no test coverage detected