From 4d1551dbb563a2ad581ea2919f2a2cd08611491c Mon Sep 17 00:00:00 2001 From: George Marques Date: Tue, 15 Jan 2019 16:03:56 -0200 Subject: GDScript autocomplete: don't carry values when guessing from `is` Guessing the type from an `is` operator should no be considered an assigment. This would cause crashes in certain scenarios. --- modules/gdscript/gdscript_editor.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 64678c7240..08ad101967 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -1181,7 +1181,11 @@ static bool _guess_identifier_type(const GDScriptCompletionContext &p_context, c c.line = op->line; c.block = blk; if (_guess_expression_type(p_context, op->arguments[1], r_type)) { - r_type.type.is_meta_type = false; + r_type.type.is_meta_type = false; // Right-hand of `is` will be a meta type, but the left-hand value is not + // Not an assignment, it shouldn't carry any value + r_type.value = Variant(); + r_type.assigned_expression = NULL; + return true; } } -- cgit v1.2.3 From 573fab744736af10925490dec6387f24c26d5416 Mon Sep 17 00:00:00 2001 From: George Marques Date: Tue, 15 Jan 2019 17:02:15 -0200 Subject: GDScript: don't check types on release builds A lot of information is missing on release, and the checks might take a performance hit. Also, having GDScript more lenient on release is usually desirable. --- modules/gdscript/gdscript_parser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index b0743af1b4..e51ce39bf3 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -8110,6 +8110,7 @@ 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); @@ -8124,7 +8125,6 @@ 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 From b0c3a3f2da3f91a4a8fe41b98a814809fff7a9f1 Mon Sep 17 00:00:00 2001 From: George Marques Date: Tue, 15 Jan 2019 18:18:03 -0200 Subject: GDScript: allow objects to be keys of dictionaries The engine allows this already, so the parser should not fail in this case. --- modules/gdscript/gdscript_parser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index e51ce39bf3..4bfa83ee3b 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -6224,7 +6224,7 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) { if (check_types && index_type.has_type) { if (base_type.kind == DataType::BUILTIN) { // Check if indexing is valid - bool error = index_type.kind != DataType::BUILTIN; + bool error = index_type.kind != DataType::BUILTIN && base_type.builtin_type != Variant::DICTIONARY; if (!error) { switch (base_type.builtin_type) { // Expect int or real as index -- cgit v1.2.3 From 4f72c6be8a7eb1876fc1c6ea35eadf31c81a674a Mon Sep 17 00:00:00 2001 From: George Marques Date: Tue, 15 Jan 2019 19:15:19 -0200 Subject: GDScript: consider constructors as always existing There's always a constructor, even if implicit, especially for native types. Also don't check for signature match on function call, since this information is not available in release builds. --- modules/gdscript/gdscript_parser.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 4bfa83ee3b..160fc48f92 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -6767,10 +6767,10 @@ GDScriptParser::DataType GDScriptParser::_reduce_function_call_type(const Operat valid = _get_function_signature(base_type, callee_name, return_type, arg_types, default_args_count, is_static, is_vararg); - if (valid) { - return_type = original_type; - return_type.is_meta_type = false; - } + return_type = original_type; + return_type.is_meta_type = false; + + valid = true; // There's always an initializer, we can asume this is true } if (!valid) { @@ -6829,6 +6829,7 @@ GDScriptParser::DataType GDScriptParser::_reduce_function_call_type(const Operat } break; } +#ifdef DEBUG_ENABLED if (!check_types) { return return_type; } @@ -6854,11 +6855,9 @@ GDScriptParser::DataType GDScriptParser::_reduce_function_call_type(const Operat if (!par_type.has_type) { _mark_line_as_unsafe(p_call->line); -#ifdef DEBUG_ENABLED if (par_type.may_yield && p_call->arguments[i]->type == Node::TYPE_OPERATOR) { _add_warning(GDScriptWarning::FUNCTION_MAY_YIELD, p_call->line, _find_function_name(static_cast(p_call->arguments[i]))); } -#endif // DEBUG_ENABLED } else if (!_is_type_compatible(arg_types[i - arg_diff], par_type, true)) { // Supertypes are acceptable for dynamic compliance if (!_is_type_compatible(par_type, arg_types[i - arg_diff])) { @@ -6871,14 +6870,14 @@ GDScriptParser::DataType GDScriptParser::_reduce_function_call_type(const Operat _mark_line_as_unsafe(p_call->line); } } else { -#ifdef DEBUG_ENABLED if (arg_type.kind == DataType::BUILTIN && arg_type.builtin_type == Variant::INT && par_type.kind == DataType::BUILTIN && par_type.builtin_type == Variant::REAL) { _add_warning(GDScriptWarning::NARROWING_CONVERSION, p_call->line, callee_name); } -#endif // DEBUG_ENABLED } } +#endif // DEBUG_ENABLED + return return_type; } -- cgit v1.2.3 From 31433ae8e4159d01ed57c334c72eb8593185b145 Mon Sep 17 00:00:00 2001 From: George Marques Date: Tue, 15 Jan 2019 19:50:48 -0200 Subject: GDScript: check for underscore prefix when type-checking Some classes are represented internally with an underscore prefix, so we need to make sure we match this representation when type-checking, otherwise the check might fail on a valid scenario. --- modules/gdscript/gdscript_function.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/gdscript/gdscript_function.h b/modules/gdscript/gdscript_function.h index aab1af1250..f4058664ff 100644 --- a/modules/gdscript/gdscript_function.h +++ b/modules/gdscript/gdscript_function.h @@ -74,8 +74,14 @@ struct GDScriptDataType { return false; } Object *obj = p_variant.operator Object *(); - if (obj && !ClassDB::is_parent_class(obj->get_class_name(), native_type)) { - return false; + if (obj) { + if (!ClassDB::is_parent_class(obj->get_class_name(), native_type)) { + // Try with underscore prefix + StringName underscore_native_type = "_" + native_type; + if (!ClassDB::is_parent_class(obj->get_class_name(), underscore_native_type)) { + return false; + } + } } return true; } break; -- cgit v1.2.3