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

Commit

Permalink
Fix array creation implicit size variable conversion
Browse files Browse the repository at this point in the history
- Fix issues when you pass a non-int32 variable into an array creation expression, reported by Ureishi
  • Loading branch information
MerlinVR committed Mar 27, 2021
1 parent 4042459 commit 4ae86a3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Assets/UdonSharp/Editor/UdonSharpASTVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,26 @@ public override void VisitArrayCreationExpression(ArrayCreationExpressionSyntax
}
else
{
SymbolDefinition capturedRank;

using (ExpressionCaptureScope rankCapture = new ExpressionCaptureScope(visitorContext, null))
{
Visit(node.Type.RankSpecifiers[0]);
arrayRankSymbol = rankCapture.ExecuteGet();
capturedRank = rankCapture.ExecuteGet();
}

if (capturedRank.symbolCsType == typeof(int))
{
arrayRankSymbol = capturedRank;
}
else
{
using (ExpressionCaptureScope convertScope = new ExpressionCaptureScope(visitorContext, null))
{
arrayRankSymbol = visitorContext.topTable.CreateUnnamedSymbol(typeof(int), SymbolDeclTypeFlags.Internal);
convertScope.SetToLocalSymbol(arrayRankSymbol);
convertScope.ExecuteSet(capturedRank, true);
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions Assets/UdonSharp/Tests/TestScripts/Core/ArrayTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ public void ExecuteTests()

tester.TestAssertion("Unity VideoPlayer array", unityVideoPlayerArray[0] != null && unityVideoPlayerArray[1] != null);
tester.TestAssertion("Base VRCStation array", baseVideoPlayerArray[0] != null && baseVideoPlayerArray[1] != null);

// Test implicit array rank conversions
float[] myFloatArr = new float[20U];
tester.TestAssertion("Array size implicit conversion 1", myFloatArr.Length == 20);

uint arrSize = 4;
myFloatArr = new float[arrSize];
tester.TestAssertion("Array size implicit conversion 2", myFloatArr.Length == 4);

byte arrSize2 = 30;
myFloatArr = new float[arrSize2];

tester.TestAssertion("Array size implicit conversion 3", myFloatArr.Length == 30);
}
}
}

0 comments on commit 4ae86a3

Please sign in to comment.