From ba13aae9af5c0996ff49bb2b6bbaec2f17039b4a Mon Sep 17 00:00:00 2001 From: George Marques Date: Thu, 17 Jan 2019 16:03:15 -0200 Subject: GDScript: allow local classes to be used as types --- modules/gdscript/gdscript_parser.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'modules') diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index a012ccad30..ebc83b45a9 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -5438,6 +5438,12 @@ GDScriptParser::DataType GDScriptParser::_resolve_type(const DataType &p_source, // Inner classes ClassNode *outer_class = p; while (outer_class) { + if (outer_class->name == id) { + found = true; + result.kind = DataType::CLASS; + result.class_type = outer_class; + break; + } for (int i = 0; i < outer_class->subclasses.size(); i++) { if (outer_class->subclasses[i] == p) { continue; -- cgit v1.2.3 From f4546fc0cdd64776f5214c3bd9b084cfda39d3d2 Mon Sep 17 00:00:00 2001 From: George Marques Date: Thu, 17 Jan 2019 16:19:12 -0200 Subject: GDScript: don't allow calling non-static function from script --- modules/gdscript/gdscript.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 9d263aa5e1..ae70525de5 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -642,7 +642,8 @@ Variant GDScript::call(const StringName &p_method, const Variant **p_args, int p if (E) { if (!E->get()->is_static()) { - WARN_PRINT(String("Can't call non-static function: '" + String(p_method) + "' in script.").utf8().get_data()); + ERR_EXPLAIN("Can't call non-static function: '" + String(p_method) + "' in script."); + ERR_FAIL_V(Variant()); } return E->get()->call(NULL, p_args, p_argcount, r_error); -- cgit v1.2.3 From f439397126f13cd29373e9ae95b963ce92094e25 Mon Sep 17 00:00:00 2001 From: George Marques Date: Thu, 17 Jan 2019 19:17:06 -0200 Subject: GDScript: read constants from parent scripts This is needed to create export variables from enums defined in a parent class. --- modules/gdscript/gdscript_parser.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'modules') diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index ebc83b45a9..2587943e76 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -811,6 +811,21 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s expr = constant; bfn = true; } + + // Check parents for the constant + if (!bfn && cln->extends_file != StringName()) { + Ref parent = ResourceLoader::load(cln->extends_file); + if (parent.is_valid() && parent->is_valid()) { + Map parent_constants; + parent->get_constants(&parent_constants); + if (parent_constants.has(identifier)) { + ConstantNode *constant = alloc_node(); + constant->value = parent_constants[identifier]; + expr = constant; + bfn = true; + } + } + } } if (!bfn) { -- cgit v1.2.3 From 8464cce857a652c06e7ff22a89c3ad88f3101d98 Mon Sep 17 00:00:00 2001 From: George Marques Date: Wed, 23 Jan 2019 18:06:58 -0200 Subject: GDScript: fix default value for autoexported typed vars --- modules/gdscript/gdscript_parser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 2587943e76..187a9979c7 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -4682,7 +4682,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } } #ifdef TOOLS_ENABLED - if (subexpr->type == Node::TYPE_CONSTANT && member._export.type != Variant::NIL) { + if (subexpr->type == Node::TYPE_CONSTANT && (member._export.type != Variant::NIL || member.data_type.has_type)) { ConstantNode *cn = static_cast(subexpr); if (cn->value.get_type() != Variant::NIL) { -- cgit v1.2.3 From 587c1c90cff876c27e4efc14fe976386dc7c85b4 Mon Sep 17 00:00:00 2001 From: George Marques Date: Wed, 23 Jan 2019 18:45:33 -0200 Subject: 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. --- modules/gdscript/gdscript_parser.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'modules') 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 > warning_skips = tokenizer->get_warning_skips(); bool warning_is_error = GLOBAL_GET("debug/gdscript/warnings/treat_warnings_as_errors").booleanize(); -- cgit v1.2.3