From ab7c2fcc84c9236358f8a7d0700eebe27597acb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=86=E3=82=8C=E3=81=84=E3=81=97?= <57707826+ureishi@users.noreply.github.com> Date: Fri, 12 May 2023 11:22:41 +0900 Subject: [PATCH] Fix strip unary plus operator Fix an issue that caused a compilation error when a variable name was preceded by a unary plus operator. --- .../Editor/Compiler/Binder/BinderSyntaxVisitor.cs | 2 +- .../Tests~/TestScripts/Core/ArithmeticTest.cs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Packages/com.vrchat.UdonSharp/Editor/Compiler/Binder/BinderSyntaxVisitor.cs b/Packages/com.vrchat.UdonSharp/Editor/Compiler/Binder/BinderSyntaxVisitor.cs index c7204d1c..3d5af66f 100644 --- a/Packages/com.vrchat.UdonSharp/Editor/Compiler/Binder/BinderSyntaxVisitor.cs +++ b/Packages/com.vrchat.UdonSharp/Editor/Compiler/Binder/BinderSyntaxVisitor.cs @@ -42,7 +42,7 @@ public override BoundNode Visit(SyntaxNode node) // Strip unary plus operator if (node.Kind() == SyntaxKind.UnaryPlusExpression) - return Visit((node as PrefixUnaryExpressionSyntax)?.Operand); + return VisitExpression((node as PrefixUnaryExpressionSyntax)?.Operand); Symbol nodeSymbol = GetSymbol(node); if (nodeSymbol is TypeSymbol) diff --git a/Packages/com.vrchat.UdonSharp/Tests~/TestScripts/Core/ArithmeticTest.cs b/Packages/com.vrchat.UdonSharp/Tests~/TestScripts/Core/ArithmeticTest.cs index 669447be..efd03787 100644 --- a/Packages/com.vrchat.UdonSharp/Tests~/TestScripts/Core/ArithmeticTest.cs +++ b/Packages/com.vrchat.UdonSharp/Tests~/TestScripts/Core/ArithmeticTest.cs @@ -34,6 +34,7 @@ public void ExecuteTests() UdonBehaviourFieldCompoundAssignment(); NullEquals(); CastCharToFloat(); + UnaryPlus(); } void IntBinaryOps() @@ -481,5 +482,11 @@ void CastCharToFloat() tester.TestAssertion("Cast char to double", c == 97.0); tester.TestAssertion("Cast char to decimal", c == 97m); } + + void UnaryPlus() + { + int n = 1; + tester.TestAssertion("Strip unary plus operator", +n == 1); + } } } \ No newline at end of file