Skip to content

Commit

Permalink
Add support for using any integer numeric type as input for an array …
Browse files Browse the repository at this point in the history
…indexer

- This will need to be revisited if VRC adds collections that have non-int indexers
  • Loading branch information
MerlinVR committed Mar 2, 2020
1 parent a6ec5df commit a9c4d87
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,16 @@ public void HandleArrayIndexerAccess(SymbolDefinition indexerSymbol)
if (!returnType.IsArray/* && returnType != typeof(string)*/) // Uncomment the check for string when VRC has added the actual indexer function to Udon.
throw new System.Exception("Can only run array indexers on array types");

bool isCastValid = (indexerSymbol.symbolCsType == typeof(int) || UdonSharpUtils.GetNumericConversionMethod(typeof(int), indexerSymbol.symbolCsType) != null) &&
indexerSymbol.symbolCsType.IsValueType &&
indexerSymbol.symbolCsType != typeof(float) && indexerSymbol.symbolCsType != typeof(float) && indexerSymbol.symbolCsType != typeof(decimal);

// This will need to be changed if Udon ever exposes collections with non-int indexers
if (isCastValid)
indexerSymbol = CastSymbolToType(indexerSymbol, typeof(int), true);
else
indexerSymbol = CastSymbolToType(indexerSymbol, typeof(int), false); // Non-explicit cast to handle if any types have implicit conversion operators and throw an error otherwise

SymbolDefinition newAccessSymbol = ExecuteGet();

accessSymbol = newAccessSymbol;
Expand Down

0 comments on commit a9c4d87

Please sign in to comment.