summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Marques <george@gmarqu.es>2019-01-23 18:45:33 -0200
committerGeorge Marques <george@gmarqu.es>2019-01-23 18:45:33 -0200
commit587c1c90cff876c27e4efc14fe976386dc7c85b4 (patch)
treea774a09897dedeb2fff70c8f1c49ee6d1cc2ad1f
parent8464cce857a652c06e7ff22a89c3ad88f3101d98 (diff)
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.
-rw-r--r--modules/gdscript/gdscript_parser.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp
index 187a9979c7..af189fdb7e 100644
--- a/modules/gdscript/gdscript_parser.cpp
+++ b/modules/gdscript/gdscript_parser.cpp
@@ -7298,7 +7298,7 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) {
DataType cont = _resolve_type(c.type, 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() + ").",
c.expression->line);
return;
@@ -7342,7 +7342,7 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) {
if (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
if (_is_type_compatible(expr_type, v.data_type)) {
_mark_line_as_unsafe(v.line);
@@ -7804,7 +7804,7 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
return;
}
- if (!lh_type.has_type) {
+ if (!lh_type.has_type && check_types) {
if (op->arguments[0]->type == Node::TYPE_OPERATOR) {
_mark_line_as_unsafe(op->line);
}
@@ -7826,7 +7826,7 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
bool valid = false;
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() +
"') to assignment operator '" + Variant::get_operator_name(oper) + "'.",
op->line);
@@ -7849,7 +7849,7 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
}
#endif // DEBUG_ENABLED
- if (!_is_type_compatible(lh_type, rh_type)) {
+ if (check_types && !_is_type_compatible(lh_type, rh_type)) {
// Try supertype test
if (_is_type_compatible(rh_type, lh_type)) {
_mark_line_as_unsafe(op->line);
@@ -7885,9 +7885,11 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
#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)) {
_mark_line_as_unsafe(op->line);
}
+#endif // DEBUG_ENABLED
} break;
case OperatorNode::OP_CALL:
case OperatorNode::OP_PARENT_CALL: {
@@ -8124,7 +8126,6 @@ Error GDScriptParser::_parse(const String &p_base_path) {
check_types = false;
#endif
-#ifdef DEBUG_ENABLED
// Resolve all class-level stuff before getting into function blocks
_check_class_level_types(main_class);
@@ -8139,6 +8140,8 @@ Error GDScriptParser::_parse(const String &p_base_path) {
return ERR_PARSE_ERROR;
}
+#ifdef DEBUG_ENABLED
+
// Resolve warning ignores
Vector<Pair<int, String> > warning_skips = tokenizer->get_warning_skips();
bool warning_is_error = GLOBAL_GET("debug/gdscript/warnings/treat_warnings_as_errors").booleanize();