1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-28 12:35:59 +02:00

Improved method selection for extension methods with generic 'this'

This commit is contained in:
Brian Fiete 2025-06-12 06:19:41 +02:00
parent cc107ae341
commit e64e421feb
2 changed files with 30 additions and 3 deletions

View file

@ -953,6 +953,13 @@ void BfMethodMatcher::CompareMethods(BfMethodInstance* prevMethodInstance, BfTyp
isBetter = true; isBetter = true;
else if ((wasArgDeferred) && (paramType != prevParamType) && (prevParamType == arg.mType) && (prevParamType == resolvedArg->mBestBoundType)) else if ((wasArgDeferred) && (paramType != prevParamType) && (prevParamType == arg.mType) && (prevParamType == resolvedArg->mBestBoundType))
isWorse = true; isWorse = true;
else if ((argIdx == -1) && (anyIsExtension))
{
if ((newMethodInstance->mMethodDef->mMethodType == BfMethodType_Extension) && (wasGenericParam) && (!prevWasGenericParam))
isWorse = true;
else if ((prevMethodInstance->mMethodDef->mMethodType == BfMethodType_Extension) && (prevWasGenericParam) && (!wasGenericParam))
isBetter = true;
}
else else
{ {
bool canCastFromCurToPrev = mModule->CanCast(mModule->GetFakeTypedValue(paramType), prevParamType, implicitCastFlags); bool canCastFromCurToPrev = mModule->CanCast(mModule->GetFakeTypedValue(paramType), prevParamType, implicitCastFlags);

View file

@ -319,6 +319,17 @@ namespace Tests
Test.Assert((ms.mVal == 1) && (ms.mVal2 == 111) && (ms.mVal3 == 222)); Test.Assert((ms.mVal == 1) && (ms.mVal2 == 111) && (ms.mVal3 == 222));
ms = .(1, 2); ms = .(1, 2);
Test.Assert((ms.mVal == 1) && (ms.mVal2 == 2) && (ms.mVal3 == 222)); Test.Assert((ms.mVal == 1) && (ms.mVal2 == 2) && (ms.mVal3 == 222));
List<int32> intList = scope .();
for (int32 i < 100)
intList.Add(i);
Span<int32> intSpan = intList;
var span = intSpan.ToRawData();
Test.Assert(span.Length == 400);
span = ((int32)123).ToRawData();
Test.Assert(span.Length == 4);
} }
[Test] [Test]
@ -430,3 +441,12 @@ namespace Tests
} }
} }
} }
static
{
public static Span<uint8> ToRawData<T>(this T self) where T : struct
{
#unwarn
return .((uint8*)&self, sizeof(T));
}
}