Skip to content

Commit

Permalink
Fix that method and property, from user script containing property is…
Browse files Browse the repository at this point in the history
… not executed.
  • Loading branch information
ChanyaVRC committed Jul 18, 2021
1 parent 308e752 commit d9f5b6b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
20 changes: 10 additions & 10 deletions Assets/UdonSharp/Editor/UdonSharpCompilationModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ public CompileTaskResult Compile(List<ClassDefinition> classDefinitions, Microso
debugInfo = new ClassDebugInfo(sourceCode, settings == null || settings.includeInlineCode);
}

PropertyVisitor propertyVisitor = new PropertyVisitor(resolver, moduleSymbols, moduleLabels);
MethodVisitor methodVisitor = new MethodVisitor(resolver, moduleSymbols, moduleLabels);

try
{
propertyVisitor.Visit(syntaxTree.GetRoot());
methodVisitor.Visit(syntaxTree.GetRoot());
}
catch (System.Exception e)
{
LogException(result, e, propertyVisitor.visitorContext.currentNode, out string logMessage);
LogException(result, e, methodVisitor.visitorContext.currentNode, out string logMessage);

programAsset.compileErrors.Add(logMessage);

Expand All @@ -104,16 +104,15 @@ public CompileTaskResult Compile(List<ClassDefinition> classDefinitions, Microso
if (ErrorCount > 0)
return result;

UdonSharpFieldVisitor fieldVisitor = new UdonSharpFieldVisitor(fieldsWithInitializers, resolver, moduleSymbols, moduleLabels, classDefinitions, debugInfo);
fieldVisitor.visitorContext.definedProperties = propertyVisitor.definedProperties;
PropertyVisitor propertyVisitor = new PropertyVisitor(resolver, moduleSymbols, moduleLabels);

try
{
fieldVisitor.Visit(syntaxTree.GetRoot());
propertyVisitor.Visit(syntaxTree.GetRoot());
}
catch (System.Exception e)
{
LogException(result, e, fieldVisitor.visitorContext.currentNode, out string logMessage);
LogException(result, e, propertyVisitor.visitorContext.currentNode, out string logMessage);

programAsset.compileErrors.Add(logMessage);

Expand All @@ -123,15 +122,16 @@ public CompileTaskResult Compile(List<ClassDefinition> classDefinitions, Microso
if (ErrorCount > 0)
return result;

MethodVisitor methodVisitor = new MethodVisitor(resolver, moduleSymbols, moduleLabels);
UdonSharpFieldVisitor fieldVisitor = new UdonSharpFieldVisitor(fieldsWithInitializers, resolver, moduleSymbols, moduleLabels, classDefinitions, debugInfo);
fieldVisitor.visitorContext.definedProperties = propertyVisitor.definedProperties;

try
{
methodVisitor.Visit(syntaxTree.GetRoot());
fieldVisitor.Visit(syntaxTree.GetRoot());
}
catch (System.Exception e)
{
LogException(result, e, methodVisitor.visitorContext.currentNode, out string logMessage);
LogException(result, e, fieldVisitor.visitorContext.currentNode, out string logMessage);

programAsset.compileErrors.Add(logMessage);

Expand Down
6 changes: 4 additions & 2 deletions Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,8 @@ public SymbolDefinition ExecuteGet()
if (getter.type == typeof(void))
throw new System.TypeLoadException("Cannot return type of void from a get statement");

outSymbol = AllocateOutputSymbol(getter.type);

using (ExpressionCaptureScope getPropertyMethodScope = new ExpressionCaptureScope(visitorContext, null, requestedDestination))
{
getPropertyMethodScope.SetToLocalSymbol(accessSymbol);
Expand All @@ -509,8 +511,8 @@ public SymbolDefinition ExecuteGet()
getReturnScope.SetToLocalSymbol(accessSymbol);
getReturnScope.ResolveAccessToken("GetProgramVariable");

outSymbol = getReturnScope.Invoke(new SymbolDefinition[] { visitorContext.topTable.CreateConstSymbol(typeof(string), getter.returnSymbol.symbolUniqueName) });
outSymbol = CastSymbolToType(outSymbol, getter.type, true, true, outSymbol == requestedDestination ? requestedDestination : null);
SymbolDefinition externVarReturn = getReturnScope.Invoke(new SymbolDefinition[] { visitorContext.topTable.CreateConstSymbol(typeof(string), getter.returnSymbol.symbolUniqueName) });
outSymbol = CastSymbolToType(externVarReturn, getter.type, true, true, outSymbol == requestedDestination ? requestedDestination : null);
}
}
else if (captureArchetype == ExpressionCaptureArchetype.Field)
Expand Down
8 changes: 8 additions & 0 deletions Assets/UdonSharp/Tests/TestScripts/Core/PropertyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public GameObject GOCallbackTest
}
}

public PropertyTestReferenceScript referenceSource;

public void ExecuteTests()
{
PropertyTest self = this;
Expand Down Expand Up @@ -156,6 +158,12 @@ public void ExecuteTests()
SetProgramVariable(nameof(_GOCallbackTest), null);

tester.TestAssertion("Property callback modification count", goCallbackCounter == 4);

tester.TestAssertion("Property in othrer user script 1", referenceSource.Value == 1);
referenceSource._value = 2;
tester.TestAssertion("Property in othrer user script 2", referenceSource.Value == 2);
//referenceSource.Value = 3;
//tester.TestAssertion("Property in othrer user script 3", referenceSource.Value == 3);
}
}
}

0 comments on commit d9f5b6b

Please sign in to comment.