Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

Commit

Permalink
Add more descriptive errors when invalid names are used for accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
MerlinVR committed Apr 2, 2020
1 parent f92735b commit 24f6262
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -1954,7 +1960,26 @@ public void HandleGenericAccess(List<System.Type> 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)
Expand Down

0 comments on commit 24f6262

Please sign in to comment.