1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 04:22:20 +02:00

Fixed mangling issue with method overrides in extensions

This commit is contained in:
Brian Fiete 2020-11-16 07:36:34 -08:00
parent e2de5becab
commit 2e3880100b
3 changed files with 40 additions and 18 deletions

View file

@ -56,22 +56,6 @@ namespace System.Reflection
{ {
extension TypeInstance extension TypeInstance
{ {
public override Result<FieldInfo> GetField(String fieldName)
{
for (int32 i = 0; i < mFieldDataCount; i++)
{
FieldData* fieldData = &mFieldDataPtr[i];
if (fieldData.[Friend]mName == fieldName)
return FieldInfo(this, fieldData);
}
return .Err;
}
public override FieldInfo.Enumerator GetFields(BindingFlags bindingFlags = cDefaultLookup)
{
return FieldInfo.Enumerator(this, bindingFlags);
}
public override MethodInfo.Enumerator GetMethods(BindingFlags bindingFlags = cDefaultLookup) public override MethodInfo.Enumerator GetMethods(BindingFlags bindingFlags = cDefaultLookup)
{ {
return MethodInfo.Enumerator(this, bindingFlags); return MethodInfo.Enumerator(this, bindingFlags);

View file

@ -20247,10 +20247,34 @@ void BfModule::SetupIRFunction(BfMethodInstance* methodInstance, StringImpl& man
if (prevFunc) if (prevFunc)
{ {
if ((methodDef->mIsOverride) && (mCurTypeInstance->mTypeDef->mIsCombinedPartial)) if ((methodDef->mIsOverride) && (mCurTypeInstance->mTypeDef->mIsCombinedPartial))
{
mCurTypeInstance->mTypeDef->PopulateMemberSets();
BfMethodDef* nextMethod = NULL;
BfMemberSetEntry* entry = NULL;
if (mCurTypeInstance->mTypeDef->mMethodSet.TryGet(BfMemberSetEntry(methodDef), &entry))
nextMethod = (BfMethodDef*)entry->mMemberDef;
while (nextMethod != NULL)
{
auto checkMethod = nextMethod;
nextMethod = nextMethod->mNextWithSameName;
if (checkMethod == methodDef)
continue;
auto checkMethodInstance = mCurTypeInstance->mMethodInstanceGroups[checkMethod->mIdx].mDefault;
if (checkMethodInstance == NULL)
continue;
if (!CompareMethodSignatures(checkMethodInstance, mCurMethodInstance))
continue;
// Take over function
mCurMethodInstance->mIRFunction = prevFunc;
}
if (!mCurMethodInstance->mIRFunction)
{ {
BfLogSysM("Function collision from inner override erased prevFunc %p: %d\n", methodInstance, prevFunc.mId); BfLogSysM("Function collision from inner override erased prevFunc %p: %d\n", methodInstance, prevFunc.mId);
mBfIRBuilder->Func_SafeRename(prevFunc); mBfIRBuilder->Func_SafeRename(prevFunc);
} }
}
else if (methodDef->mIsExtern) else if (methodDef->mIsExtern)
{ {
// Allow this // Allow this

View file

@ -94,6 +94,17 @@ namespace Tests
} }
} }
class ClassC
{
public extern void MethodA();
public void MethodB() => MethodA();
}
extension ClassC
{
public override void MethodA() { }
}
class TClassA<T> where T : IDisposable class TClassA<T> where T : IDisposable
{ {
public int32 mA = 10; public int32 mA = 10;
@ -167,6 +178,9 @@ namespace Tests
ClassA ca = scope ClassA(); ClassA ca = scope ClassA();
ca.mA = 123; ca.mA = 123;
ca.mB = 234; ca.mB = 234;
ClassC cc = scope .();
cc.MethodB();
} }
[Test] [Test]