Skip to content

Commit

Permalink
Fix issue where user defined functions would reuse return symbol
Browse files Browse the repository at this point in the history
- Fix issue where user defined functions would reuse return symbols. This would cause unexpected behaviour if you reused the same function output multiple times without assigning it to something
  • Loading branch information
MerlinVR committed Feb 29, 2020
1 parent 41a5e8f commit 482e711
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -763,13 +763,23 @@ private SymbolDefinition InvokeLocalMethod(SymbolDefinition[] invokeParams)
restoreReturnLocationScope.ExecuteSet(oldReturnLocation);
}

SymbolDefinition returnValue = null;

if (captureLocalMethod.returnSymbol != null)
{
returnValue = visitorContext.topTable.CreateUnnamedSymbol(captureLocalMethod.returnSymbol.userCsType, SymbolDeclTypeFlags.Internal);

using (ExpressionCaptureScope returnValSetScope = new ExpressionCaptureScope(visitorContext, null))
{
returnValSetScope.SetToLocalSymbol(returnValue);
returnValSetScope.ExecuteSet(captureLocalMethod.returnSymbol);
}

if (visitorContext.topCaptureScope != null && visitorContext.topCaptureScope.IsUnknownArchetype())
visitorContext.topCaptureScope.SetToLocalSymbol(captureLocalMethod.returnSymbol);
visitorContext.topCaptureScope.SetToLocalSymbol(returnValue);
}

return captureLocalMethod.returnSymbol;
return returnValue;
}

private SymbolDefinition InvokeUserExtern(SymbolDefinition[] invokeParams)
Expand Down

0 comments on commit 482e711

Please sign in to comment.