From 24f62626a2d921c23b7bf0645d62d476705bca4c Mon Sep 17 00:00:00 2001 From: Merlin <36685500+Merlin-san@users.noreply.github.com> Date: Thu, 2 Apr 2020 13:04:45 -0700 Subject: [PATCH] Add more descriptive errors when invalid names are used for accessors --- .../Editor/UdonSharpExpressionCapture.cs | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs b/Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs index 77d7502c..2c9f2ad7 100644 --- a/Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs +++ b/Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs @@ -376,6 +376,12 @@ public SymbolDefinition ExecuteGet() // Capture type should still be valid from the last transition outSymbol = visitorContext.topTable.CreateConstSymbol(captureType, GetEnumValue()); } + else if (captureArchetype == ExpressionCaptureArchetype.Unknown) + { + string[] unresolvedTokens = unresolvedAccessChain.Split('.'); + string invalidName = unresolvedTokens.Length > 1 ? unresolvedTokens[unresolvedTokens.Length - 2] : unresolvedTokens[0]; + throw new System.Exception($"The name '{invalidName}' does not exist in the current context"); + } else { throw new System.Exception("Get can only be run on Fields, Properties, Local Symbols, array indexers, and the `this` keyword"); @@ -1954,7 +1960,26 @@ public void HandleGenericAccess(List genericArguments) private void HandleUnknownToken(string unknownToken) { if (captureArchetype != ExpressionCaptureArchetype.Unknown && captureArchetype != ExpressionCaptureArchetype.Namespace) - throw new System.Exception($"Unknown type/field/parameter/method {unresolvedAccessChain}.{unknownToken}"); + { + System.Type returnType = null; + + try + { + returnType = GetReturnType(true); + } + catch { } + + string tokenName = unresolvedAccessChain + (unresolvedAccessChain.Length != 0 ? "." : "") + unknownToken; + + if (returnType != null) + { + throw new System.Exception($"'{returnType.Name}' does not contain a definition for '{tokenName}'"); + } + else + { + throw new System.Exception($"Unknown type/field/parameter/method '{tokenName}'"); + } + } captureArchetype = ExpressionCaptureArchetype.Unknown; if (captureNamespace.Length > 0)