From 36a5737fa60bc2e80a66085603d257d54e70937f Mon Sep 17 00:00:00 2001 From: Rygor Borodoolin <6opoDuJIo@i.ua> Date: Tue, 8 Mar 2016 11:40:41 +0200 Subject: [PATCH 1/2] Meaningless check, that causes bug : we always allowed to call first called extension method in each userdata instance example : userdata.ExtMethod1() --called fine userdata.ExtMethod2() --null indexer! --- .../BasicDescriptors/DispatchingUserDataDescriptor.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/MoonSharp.Interpreter/Interop/BasicDescriptors/DispatchingUserDataDescriptor.cs b/src/MoonSharp.Interpreter/Interop/BasicDescriptors/DispatchingUserDataDescriptor.cs index bc1276b2..093838d7 100644 --- a/src/MoonSharp.Interpreter/Interop/BasicDescriptors/DispatchingUserDataDescriptor.cs +++ b/src/MoonSharp.Interpreter/Interop/BasicDescriptors/DispatchingUserDataDescriptor.cs @@ -13,7 +13,6 @@ namespace MoonSharp.Interpreter.Interop.BasicDescriptors /// public abstract class DispatchingUserDataDescriptor : IUserDataDescriptor, IOptimizableDescriptor { - private int m_ExtMethodsVersion = 0; private Dictionary m_MetaMembers = new Dictionary(); private Dictionary m_Members = new Dictionary(); @@ -236,10 +235,8 @@ public virtual DynValue Index(Script script, object obj, DynValue index, bool is if (v == null) v = TryIndex(script, obj, Camelify(index.String)); if (v == null) v = TryIndex(script, obj, UpperFirstLetter(Camelify(index.String))); - if (v == null && m_ExtMethodsVersion < UserData.GetExtensionMethodsChangeVersion()) + if (v == null) { - m_ExtMethodsVersion = UserData.GetExtensionMethodsChangeVersion(); - v = TryIndexOnExtMethod(script, obj, index.String); if (v == null) v = TryIndexOnExtMethod(script, obj, UpperFirstLetter(index.String)); if (v == null) v = TryIndexOnExtMethod(script, obj, Camelify(index.String)); From 697cb73fa1bd8b438e90548e9f1fe930f9474e52 Mon Sep 17 00:00:00 2001 From: Rygor Borodoolin <6opoDuJIo@i.ua> Date: Tue, 8 Mar 2016 19:25:37 +0200 Subject: [PATCH 2/2] Fixed calling extension methods throwing InvalidOperationException in case when multiple extension methods with similar signature were available in different extension classes, and one of the extension methods has generic argument as extendable type: TweenSettingsExtensions.SetEase(this T t, Ease ease) where T : Tween; //this one cause exception shot upon calling SetEase SpecialTweenExtensions.SetEase(this Tweener @this, Ease ease) --- .../ExtensionMethodsRegistry.cs | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/MoonSharp.Interpreter/Interop/UserDataRegistries/ExtensionMethodsRegistry.cs b/src/MoonSharp.Interpreter/Interop/UserDataRegistries/ExtensionMethodsRegistry.cs index baaf9069..262e76f4 100644 --- a/src/MoonSharp.Interpreter/Interop/UserDataRegistries/ExtensionMethodsRegistry.cs +++ b/src/MoonSharp.Interpreter/Interop/UserDataRegistries/ExtensionMethodsRegistry.cs @@ -153,17 +153,25 @@ private static MethodInfo InstantiateMethodInfo(MethodInfo mi, Type extensionTyp private static Type GetGenericMatch(Type extensionType, Type extendedType) { - extensionType = extensionType.GetGenericTypeDefinition(); - - foreach (Type t in extendedType.GetAllImplementedTypes()) - { - if (t.IsGenericType && t.GetGenericTypeDefinition() == extensionType) - { - return t; - } - } - - return null; + if (!extensionType.IsGenericParameter) + { + extensionType = extensionType.GetGenericTypeDefinition(); + + foreach (Type t in extendedType.GetAllImplementedTypes()) + { + if (t.IsGenericType && t.GetGenericTypeDefinition() == extensionType) + { + return t; + } + } + } + + /*if (extendedType.IsGenericParameter) + { + return extendedType; + }*/ + + return null; } }