Wrong extension methods caching?
In DispatchingUserDataDescriptor.cs
if (v == null && m_ExtMethodsVersion < UserData.GetExtensionMethodsChangeVersion())
{
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));
if (v == null) v = TryIndexOnExtMethod(script, obj, UpperFirstLetter(Camelify(index.String)));
}
In my case, it only work if the condition is: if (v == null && m_ExtMethodsVersion <= UserData.GetExtensionMethodsChangeVersion())
Scenario is: UserData.RegisterExtensionType(t1) UserData.RegisterExtensionType(t2) UserData.GetExtensionMethodsChangeVersion() = 2 call t1.method m_ExtMethodsVersion = 2 but now only t1.method in the cache so call t2.method failed
Yes, sounds suspicious .. I'll check asap. Thanks
No repro :( I've added Interop_Overloads_Twice_ExtMethods1 and Interop_Overloads_Twice_ExtMethods2 tests in UserDataOverloadsTest.cs ... let me know if you still have the problem or what is missing from the test...
fixed in here: https://github.com/xanathar/moonsharp/pull/130
I'm running into the same issue, #130 does fix it for me, but there will likely be impacted performance as a result as after that patch it'll always check for extension methods. Not sure the best way to handle it, maybe try caching all extension methods (rather than just the requested one) the first time you need them?
I believe this is what is going on: It seems that if you have a single DispatchingUserDataDescriptor and then call two separate extension methods on it, the second one will fail because when the first is called m_ExtMethodsVersion is set to the latest version but only the first method is cached. When the second is called, m_ExtMethodsVersion is already at latest so it doesn't try and lookup the new method and falsely assumes it was already cached.