Skip to content

Commit d14979c

Browse files
committed
Fix unary minus implicit conversion to higher precision types
- Add special case for unary minus to convert to higher precision types
1 parent 2e8d35d commit d14979c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Assets/UdonSharp/Editor/UdonSharpASTVisitor.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,8 +833,11 @@ public override void VisitPrefixUnaryExpression(PrefixUnaryExpressionSyntax node
833833
case SyntaxKind.MinusMinusToken:
834834
case SyntaxKind.PreDecrementExpression:
835835
case SyntaxKind.ExclamationToken:
836+
operatorMethods.AddRange(GetOperators(operandCapture.GetReturnType(), node.OperatorToken.Kind()));
837+
break;
836838
case SyntaxKind.MinusToken:
837839
operatorMethods.AddRange(GetOperators(operandCapture.GetReturnType(), node.OperatorToken.Kind()));
840+
operatorMethods.AddRange(GetImplicitHigherPrecisionOperator(operandCapture.GetReturnType(), null, SyntaxKindToBuiltinOperator(node.OperatorToken.Kind()), true));
838841
break;
839842
default:
840843
throw new System.NotImplementedException($"Handling for prefix token {node.OperatorToken.Kind()} is not implemented");
@@ -1130,7 +1133,7 @@ private MethodInfo[] GetImplicitHigherPrecisionOperator(System.Type lhsType, Sys
11301133

11311134
// If both are not numeric types then there will be no higher precision operator to use
11321135
// Implicit casts on the operands to higher precision types happen elsewhere
1133-
if (!UdonSharpUtils.IsNumericType(lhsType) || !UdonSharpUtils.IsNumericType(rhsType))
1136+
if (!UdonSharpUtils.IsNumericType(lhsType) || (rhsType != null && !UdonSharpUtils.IsNumericType(rhsType)))
11341137
return new MethodInfo[] { };
11351138

11361139
// There is an implcit cast already so the other type's operator should be included in operator finding already

Assets/UdonSharp/Editor/UdonSharpUtils.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ public static bool IsNumericImplicitCastValid(System.Type targetType, System.Typ
128128

129129
public static System.Type GetNextHighestNumericPrecision(System.Type type)
130130
{
131+
if (type == null)
132+
return null;
133+
131134
System.Type precisionType = null;
132135
nextHighestPrecisionType.TryGetValue(type, out precisionType);
133136

0 commit comments

Comments
 (0)