From e4330e33e6eee2da7f4460c0aef3751dca6a57a2 Mon Sep 17 00:00:00 2001 From: Ignacio Etcheverry Date: Mon, 20 Jan 2020 19:08:08 +0100 Subject: [PATCH] Mono/C#: Fix error when parsing nested generics Also fixed the editor not including the parse error message in the error. --- .../GodotTools/GodotTools/Internals/ScriptClassParser.cs | 6 +++--- modules/mono/editor/editor_internal_calls.cpp | 9 ++++++++- modules/mono/editor/script_class_parser.cpp | 6 ++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/modules/mono/editor/GodotTools/GodotTools/Internals/ScriptClassParser.cs b/modules/mono/editor/GodotTools/GodotTools/Internals/ScriptClassParser.cs index 80e45b3a3cb..11afa8773ed 100644 --- a/modules/mono/editor/GodotTools/GodotTools/Internals/ScriptClassParser.cs +++ b/modules/mono/editor/GodotTools/GodotTools/Internals/ScriptClassParser.cs @@ -25,14 +25,14 @@ namespace GodotTools.Internals } [MethodImpl(MethodImplOptions.InternalCall)] - private static extern Error internal_ParseFile(string filePath, Array classes); + private static extern Error internal_ParseFile(string filePath, Array classes, out string errorStr); public static void ParseFileOrThrow(string filePath, out IEnumerable classes) { var classesArray = new Array(); - var error = internal_ParseFile(filePath, classesArray); + var error = internal_ParseFile(filePath, classesArray, out string errorStr); if (error != Error.Ok) - throw new Exception($"Failed to determine namespace and class for script: {filePath}. Parse error: {error}"); + throw new Exception($"Failed to determine namespace and class for script: {filePath}. Parse error: {errorStr ?? error.ToString()}"); var classesList = new List(); diff --git a/modules/mono/editor/editor_internal_calls.cpp b/modules/mono/editor/editor_internal_calls.cpp index cfc869cd39d..c8d20e80be7 100644 --- a/modules/mono/editor/editor_internal_calls.cpp +++ b/modules/mono/editor/editor_internal_calls.cpp @@ -201,7 +201,9 @@ uint32_t godot_icall_BindingsGenerator_CsGlueVersion() { return CS_GLUE_VERSION; } -int32_t godot_icall_ScriptClassParser_ParseFile(MonoString *p_filepath, MonoObject *p_classes) { +int32_t godot_icall_ScriptClassParser_ParseFile(MonoString *p_filepath, MonoObject *p_classes, MonoString **r_error_str) { + *r_error_str = NULL; + String filepath = GDMonoMarshal::mono_string_to_godot(p_filepath); ScriptClassParser scp; @@ -220,6 +222,11 @@ int32_t godot_icall_ScriptClassParser_ParseFile(MonoString *p_filepath, MonoObje classDeclDict["base_count"] = classDecl.base.size(); classes.push_back(classDeclDict); } + } else { + String error_str = scp.get_error(); + if (!error_str.empty()) { + *r_error_str = GDMonoMarshal::mono_string_from_godot(error_str); + } } return err; } diff --git a/modules/mono/editor/script_class_parser.cpp b/modules/mono/editor/script_class_parser.cpp index c400479b896..84163dd9520 100644 --- a/modules/mono/editor/script_class_parser.cpp +++ b/modules/mono/editor/script_class_parser.cpp @@ -302,8 +302,10 @@ Error ScriptClassParser::_skip_generic_type_params() { Error err = _skip_generic_type_params(); if (err) return err; - continue; - } else if (tk == TK_OP_GREATER) { + tk = get_token(); + } + + if (tk == TK_OP_GREATER) { return OK; } else if (tk != TK_COMMA) { error_str = "Unexpected token: " + get_token_name(tk);