1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-25 15:37:42 +00:00

GDScript: do second pass of parsing on release

Some construct (like match) actually depends on the second pass. This
adds some extra checks to not perform specific type-checks on release
since not all type information is available.
This commit is contained in:
George Marques
2019-01-23 18:45:33 -02:00
parent 8464cce857
commit 587c1c90cf

View File

@@ -7298,7 +7298,7 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) {
DataType cont = _resolve_type(c.type, c.expression->line); DataType cont = _resolve_type(c.type, c.expression->line);
DataType expr = _resolve_type(c.expression->get_datatype(), c.expression->line); DataType expr = _resolve_type(c.expression->get_datatype(), c.expression->line);
if (!_is_type_compatible(cont, expr)) { if (check_types && !_is_type_compatible(cont, expr)) {
_set_error("Constant value type (" + expr.to_string() + ") is not compatible with declared type (" + cont.to_string() + ").", _set_error("Constant value type (" + expr.to_string() + ") is not compatible with declared type (" + cont.to_string() + ").",
c.expression->line); c.expression->line);
return; return;
@@ -7342,7 +7342,7 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) {
if (v.expression) { if (v.expression) {
DataType expr_type = _reduce_node_type(v.expression); DataType expr_type = _reduce_node_type(v.expression);
if (!_is_type_compatible(v.data_type, expr_type)) { if (check_types && !_is_type_compatible(v.data_type, expr_type)) {
// Try supertype test // Try supertype test
if (_is_type_compatible(expr_type, v.data_type)) { if (_is_type_compatible(expr_type, v.data_type)) {
_mark_line_as_unsafe(v.line); _mark_line_as_unsafe(v.line);
@@ -7804,7 +7804,7 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
return; return;
} }
if (!lh_type.has_type) { if (!lh_type.has_type && check_types) {
if (op->arguments[0]->type == Node::TYPE_OPERATOR) { if (op->arguments[0]->type == Node::TYPE_OPERATOR) {
_mark_line_as_unsafe(op->line); _mark_line_as_unsafe(op->line);
} }
@@ -7826,7 +7826,7 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
bool valid = false; bool valid = false;
rh_type = _get_operation_type(oper, lh_type, arg_type, valid); rh_type = _get_operation_type(oper, lh_type, arg_type, valid);
if (!valid) { if (check_types && !valid) {
_set_error("Invalid operand types ('" + lh_type.to_string() + "' and '" + arg_type.to_string() + _set_error("Invalid operand types ('" + lh_type.to_string() + "' and '" + arg_type.to_string() +
"') to assignment operator '" + Variant::get_operator_name(oper) + "'.", "') to assignment operator '" + Variant::get_operator_name(oper) + "'.",
op->line); op->line);
@@ -7849,7 +7849,7 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
} }
#endif // DEBUG_ENABLED #endif // DEBUG_ENABLED
if (!_is_type_compatible(lh_type, rh_type)) { if (check_types && !_is_type_compatible(lh_type, rh_type)) {
// Try supertype test // Try supertype test
if (_is_type_compatible(rh_type, lh_type)) { if (_is_type_compatible(rh_type, lh_type)) {
_mark_line_as_unsafe(op->line); _mark_line_as_unsafe(op->line);
@@ -7885,9 +7885,11 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
#endif // DEBUG_ENABLED #endif // DEBUG_ENABLED
} }
} }
#ifdef DEBUG_ENABLED
if (!rh_type.has_type && (op->op != OperatorNode::OP_ASSIGN || lh_type.has_type || op->arguments[0]->type == Node::TYPE_OPERATOR)) { if (!rh_type.has_type && (op->op != OperatorNode::OP_ASSIGN || lh_type.has_type || op->arguments[0]->type == Node::TYPE_OPERATOR)) {
_mark_line_as_unsafe(op->line); _mark_line_as_unsafe(op->line);
} }
#endif // DEBUG_ENABLED
} break; } break;
case OperatorNode::OP_CALL: case OperatorNode::OP_CALL:
case OperatorNode::OP_PARENT_CALL: { case OperatorNode::OP_PARENT_CALL: {
@@ -8124,7 +8126,6 @@ Error GDScriptParser::_parse(const String &p_base_path) {
check_types = false; check_types = false;
#endif #endif
#ifdef DEBUG_ENABLED
// Resolve all class-level stuff before getting into function blocks // Resolve all class-level stuff before getting into function blocks
_check_class_level_types(main_class); _check_class_level_types(main_class);
@@ -8139,6 +8140,8 @@ Error GDScriptParser::_parse(const String &p_base_path) {
return ERR_PARSE_ERROR; return ERR_PARSE_ERROR;
} }
#ifdef DEBUG_ENABLED
// Resolve warning ignores // Resolve warning ignores
Vector<Pair<int, String> > warning_skips = tokenizer->get_warning_skips(); Vector<Pair<int, String> > warning_skips = tokenizer->get_warning_skips();
bool warning_is_error = GLOBAL_GET("debug/gdscript/warnings/treat_warnings_as_errors").booleanize(); bool warning_is_error = GLOBAL_GET("debug/gdscript/warnings/treat_warnings_as_errors").booleanize();