diff --git a/Assets/UdonSharp/Editor/UdonSharpASTVisitor.cs b/Assets/UdonSharp/Editor/UdonSharpASTVisitor.cs index 2963823f..1d3b044c 100644 --- a/Assets/UdonSharp/Editor/UdonSharpASTVisitor.cs +++ b/Assets/UdonSharp/Editor/UdonSharpASTVisitor.cs @@ -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); + } } } diff --git a/Assets/UdonSharp/Tests/TestScripts/Core/ArrayTest.cs b/Assets/UdonSharp/Tests/TestScripts/Core/ArrayTest.cs index 17091f94..85420726 100644 --- a/Assets/UdonSharp/Tests/TestScripts/Core/ArrayTest.cs +++ b/Assets/UdonSharp/Tests/TestScripts/Core/ArrayTest.cs @@ -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); } } }