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

Commit

Permalink
Fix GetComponent on UdonSharpBehaviour variables
Browse files Browse the repository at this point in the history
- Fix GetComponent variants on UdonSharpBehaviour variables
  • Loading branch information
MerlinVR committed Nov 27, 2020
1 parent 18bf9a8 commit 409c2e1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
39 changes: 25 additions & 14 deletions Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1375,25 +1375,36 @@ private SymbolDefinition InvokeExtern(SymbolDefinition[] invokeParams)
if (targetMethod == null)
{
targetMethod = visitorContext.resolverContext.FindBestOverloadFunction(captureMethods, invokeParams.Select(e => e.symbolCsType).ToList(), false);
if (targetMethod != null)
{
throw new System.Exception($"Method is not exposed to Udon: {targetMethod}, Udon signature: {visitorContext.resolverContext.GetUdonMethodName(targetMethod, false)}");
}

string udonFilteredMethods = "";

udonFilteredMethods = string.Join("\n", captureMethods
.Select(e => new System.Tuple<MethodBase, string>(e, visitorContext.resolverContext.GetUdonMethodName(e, false)))
.Where(e => !visitorContext.resolverContext.IsValidUdonMethod(e.Item2))
.Select(e => e.Item1));

if (udonFilteredMethods.Length > 0)
if (targetMethod != null &&
targetMethod.ReflectedType == typeof(VRC.Udon.UdonBehaviour) &&
targetMethod.Name.StartsWith("GetComponent") &&
((MethodInfo)targetMethod).ReturnType.IsGenericParameter)
{
throw new System.Exception($"Could not find valid method that exists in Udon.\nList of applicable methods that do not exist:\n{udonFilteredMethods}");
// Uhh just skip the else stuff
}
else
{
throw new System.Exception("Could not find valid method for given parameters!");
if (targetMethod != null)
{
throw new System.Exception($"Method is not exposed to Udon: {targetMethod}, Udon signature: {visitorContext.resolverContext.GetUdonMethodName(targetMethod, false)}");
}

string udonFilteredMethods = "";

udonFilteredMethods = string.Join("\n", captureMethods
.Select(e => new System.Tuple<MethodBase, string>(e, visitorContext.resolverContext.GetUdonMethodName(e, false)))
.Where(e => !visitorContext.resolverContext.IsValidUdonMethod(e.Item2))
.Select(e => e.Item1));

if (udonFilteredMethods.Length > 0)
{
throw new System.Exception($"Could not find valid method that exists in Udon.\nList of applicable methods that do not exist:\n{udonFilteredMethods}");
}
else
{
throw new System.Exception("Could not find valid method for given parameters!");
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions Assets/UdonSharp/Tests/TestScripts/Core/MethodCallsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public void ExecuteTests()
tester.TestAssertion("Vector3 indexer", new Vector3(1f, 2f)[1] == 2f);
tester.TestAssertion("Vector4 indexer", new Vector4(1f, 2f)[1] == 2f);
tester.TestAssertion("Matrix4x4 indexer", Matrix4x4.identity[0] == 1f && Matrix4x4.identity[1] == 0f);

tester.TestAssertion("U# Behaviour GetComponent", tester.GetComponent<IntegrationTestSuite>() != null);
tester.TestAssertion("UdonBehaviour GetComponent", ((UdonBehaviour)(Component)tester).GetComponent<IntegrationTestSuite>() != null);
}

//public void test(int a, bool b, float c = 5f, params float[] d)
Expand Down

0 comments on commit 409c2e1

Please sign in to comment.