mirror of
				https://github.com/godotengine/godot.git
				synced 2025-10-31 21:51:22 +00:00 
			
		
		
		
	GDScript: Fix UNSAFE_CALL_ARGUMENT warning for Variant constructors
				
					
				
			This commit is contained in:
		
							parent
							
								
									19890614c6
								
							
						
					
					
						commit
						ba96d4f631
					
				
					 5 changed files with 78 additions and 24 deletions
				
			
		|  | @ -3022,9 +3022,23 @@ void GDScriptAnalyzer::reduce_call(GDScriptParser::CallNode *p_call, bool p_is_a | |||
| 					} else { | ||||
| #ifdef DEBUG_ENABLED | ||||
| 						mark_node_unsafe(p_call); | ||||
| 						// We don't know what type was expected since constructors support overloads.
 | ||||
| 						// TODO: Improve this by checking for matching candidates?
 | ||||
| 						parser->push_warning(p_call->arguments[0], GDScriptWarning::UNSAFE_CALL_ARGUMENT, "1", function_name, "<unknown type>", "Variant"); | ||||
| 						// Constructors support overloads.
 | ||||
| 						Vector<String> types; | ||||
| 						for (int i = 0; i < Variant::VARIANT_MAX; i++) { | ||||
| 							if (i != builtin_type && Variant::can_convert_strict((Variant::Type)i, builtin_type)) { | ||||
| 								types.push_back(Variant::get_type_name((Variant::Type)i)); | ||||
| 							} | ||||
| 						} | ||||
| 						String expected_types = function_name; | ||||
| 						if (types.size() == 1) { | ||||
| 							expected_types += "\" or \"" + types[0]; | ||||
| 						} else if (types.size() >= 2) { | ||||
| 							for (int i = 0; i < types.size() - 1; i++) { | ||||
| 								expected_types += "\", \"" + types[i]; | ||||
| 							} | ||||
| 							expected_types += "\", or \"" + types[types.size() - 1]; | ||||
| 						} | ||||
| 						parser->push_warning(p_call->arguments[0], GDScriptWarning::UNSAFE_CALL_ARGUMENT, "1", "constructor", function_name, expected_types, "Variant"); | ||||
| #endif | ||||
| 						p_call->set_datatype(call_type); | ||||
| 						return; | ||||
|  | @ -3069,9 +3083,9 @@ void GDScriptAnalyzer::reduce_call(GDScriptParser::CallNode *p_call, bool p_is_a | |||
| #ifdef DEBUG_ENABLED | ||||
| 							if (!(par_type.is_variant() && par_type.is_hard_type())) { | ||||
| 								GDScriptParser::DataType arg_type = p_call->arguments[i]->get_datatype(); | ||||
| 								if (arg_type.is_variant() || !arg_type.is_hard_type() || !is_type_compatible(arg_type, par_type, true)) { | ||||
| 								if (arg_type.is_variant() || !arg_type.is_hard_type()) { | ||||
| 									mark_node_unsafe(p_call); | ||||
| 									parser->push_warning(p_call->arguments[i], GDScriptWarning::UNSAFE_CALL_ARGUMENT, itos(i + 1), function_name, par_type.to_string(), arg_type.to_string_strict()); | ||||
| 									parser->push_warning(p_call->arguments[i], GDScriptWarning::UNSAFE_CALL_ARGUMENT, itos(i + 1), "constructor", function_name, par_type.to_string(), arg_type.to_string_strict()); | ||||
| 								} | ||||
| 							} | ||||
| #endif | ||||
|  | @ -5057,7 +5071,7 @@ void GDScriptAnalyzer::validate_call_arg(const List<GDScriptParser::DataType> &p | |||
| 			// Argument can be anything, so this is unsafe (unless the parameter is a hard variant).
 | ||||
| 			if (!(par_type.is_hard_type() && par_type.is_variant())) { | ||||
| 				mark_node_unsafe(p_call->arguments[i]); | ||||
| 				parser->push_warning(p_call->arguments[i], GDScriptWarning::UNSAFE_CALL_ARGUMENT, itos(i + 1), p_call->function_name, par_type.to_string(), arg_type.to_string_strict()); | ||||
| 				parser->push_warning(p_call->arguments[i], GDScriptWarning::UNSAFE_CALL_ARGUMENT, itos(i + 1), "function", p_call->function_name, par_type.to_string(), arg_type.to_string_strict()); | ||||
| 			} | ||||
| #endif | ||||
| 		} else if (par_type.is_hard_type() && !is_type_compatible(par_type, arg_type, true)) { | ||||
|  | @ -5069,7 +5083,7 @@ void GDScriptAnalyzer::validate_call_arg(const List<GDScriptParser::DataType> &p | |||
| 			} else { | ||||
| 				// Supertypes are acceptable for dynamic compliance, but it's unsafe.
 | ||||
| 				mark_node_unsafe(p_call); | ||||
| 				parser->push_warning(p_call->arguments[i], GDScriptWarning::UNSAFE_CALL_ARGUMENT, itos(i + 1), p_call->function_name, par_type.to_string(), arg_type.to_string_strict()); | ||||
| 				parser->push_warning(p_call->arguments[i], GDScriptWarning::UNSAFE_CALL_ARGUMENT, itos(i + 1), "function", p_call->function_name, par_type.to_string(), arg_type.to_string_strict()); | ||||
| #endif | ||||
| 			} | ||||
| #ifdef DEBUG_ENABLED | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Danil Alexeev
						Danil Alexeev