From 409c2e1664970adc97a65726c86faa25610120f1 Mon Sep 17 00:00:00 2001 From: Merlin <36685500+Merlin-san@users.noreply.github.com> Date: Fri, 27 Nov 2020 00:00:58 -0800 Subject: [PATCH] Fix GetComponent on UdonSharpBehaviour variables - Fix GetComponent variants on UdonSharpBehaviour variables --- .../Editor/UdonSharpExpressionCapture.cs | 39 ++++++++++++------- .../Tests/TestScripts/Core/MethodCallsTest.cs | 3 ++ 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs b/Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs index dba5624e..d2d46c5b 100644 --- a/Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs +++ b/Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs @@ -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(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(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!"); + } } } diff --git a/Assets/UdonSharp/Tests/TestScripts/Core/MethodCallsTest.cs b/Assets/UdonSharp/Tests/TestScripts/Core/MethodCallsTest.cs index 164ed487..193bb08b 100644 --- a/Assets/UdonSharp/Tests/TestScripts/Core/MethodCallsTest.cs +++ b/Assets/UdonSharp/Tests/TestScripts/Core/MethodCallsTest.cs @@ -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() != null); + tester.TestAssertion("UdonBehaviour GetComponent", ((UdonBehaviour)(Component)tester).GetComponent() != null); } //public void test(int a, bool b, float c = 5f, params float[] d)