mirror of
				https://github.com/godotengine/godot.git
				synced 2025-10-31 13:41:03 +00:00 
			
		
		
		
	GDScript: Forbid using "script" as member name
Avoids the user breaking things by creating a "script" variable with something else, effectively overwriting the "script" slot on Object.
This commit is contained in:
		
							parent
							
								
									1c9e71e7d0
								
							
						
					
					
						commit
						4c20d9407d
					
				
					 1 changed files with 9 additions and 3 deletions
				
			
		|  | @ -7648,6 +7648,11 @@ GDScriptParser::DataType GDScriptParser::_reduce_identifier_type(const DataType | |||
| 
 | ||||
| void GDScriptParser::_check_class_level_types(ClassNode *p_class) { | ||||
| 
 | ||||
| 	// Names of internal object properties that we check to avoid overriding them.
 | ||||
| 	// "__meta__" could also be in here, but since it doesn't really affect object metadata,
 | ||||
| 	// it is okay to override it on script.
 | ||||
| 	StringName script_name = CoreStringNames::get_singleton()->_script; | ||||
| 
 | ||||
| 	_mark_line_as_safe(p_class->line); | ||||
| 
 | ||||
| 	// Constants
 | ||||
|  | @ -7668,8 +7673,9 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) { | |||
| 		c.expression->set_datatype(expr); | ||||
| 
 | ||||
| 		DataType tmp; | ||||
| 		if (_get_member_type(p_class->base_type, E->key(), tmp)) { | ||||
| 			_set_error("The member \"" + String(E->key()) + "\" already exists in a parent class.", c.expression->line); | ||||
| 		const StringName &constant_name = E->key(); | ||||
| 		if (constant_name == script_name || _get_member_type(p_class->base_type, constant_name, tmp)) { | ||||
| 			_set_error("The member \"" + String(constant_name) + "\" already exists in a parent class.", c.expression->line); | ||||
| 			return; | ||||
| 		} | ||||
| 	} | ||||
|  | @ -7690,7 +7696,7 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) { | |||
| 		ClassNode::Member &v = p_class->variables.write[i]; | ||||
| 
 | ||||
| 		DataType tmp; | ||||
| 		if (_get_member_type(p_class->base_type, v.identifier, tmp)) { | ||||
| 		if (v.identifier == script_name || _get_member_type(p_class->base_type, v.identifier, tmp)) { | ||||
| 			_set_error("The member \"" + String(v.identifier) + "\" already exists in a parent class.", v.line); | ||||
| 			return; | ||||
| 		} | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 George Marques
						George Marques