mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 04:22:20 +02:00
Fixed indexer method selection
This commit is contained in:
parent
29832cb3bb
commit
35a81b7bbe
2 changed files with 45 additions and 35 deletions
|
@ -20981,16 +20981,14 @@ void BfExprEvaluator::Visit(BfIndexerExpression* indexerExpr)
|
||||||
{
|
{
|
||||||
bool isFailurePass = pass == 1;
|
bool isFailurePass = pass == 1;
|
||||||
|
|
||||||
|
BfPropertyDef* foundProp = NULL;
|
||||||
|
BfTypeInstance* foundPropTypeInst = NULL;
|
||||||
|
|
||||||
auto curCheckType = startCheckTypeInst;
|
auto curCheckType = startCheckTypeInst;
|
||||||
while (curCheckType != NULL)
|
while (curCheckType != NULL)
|
||||||
{
|
{
|
||||||
BfProtectionCheckFlags protectionCheckFlags = BfProtectionCheckFlag_None;
|
BfProtectionCheckFlags protectionCheckFlags = BfProtectionCheckFlag_None;
|
||||||
|
|
||||||
BfPropertyDef* foundProp = NULL;
|
|
||||||
BfTypeInstance* foundPropTypeInst = NULL;
|
|
||||||
|
|
||||||
int matchedIndexCount = 0;
|
|
||||||
|
|
||||||
curCheckType->mTypeDef->PopulateMemberSets();
|
curCheckType->mTypeDef->PopulateMemberSets();
|
||||||
|
|
||||||
BfMemberSetEntry* entry;
|
BfMemberSetEntry* entry;
|
||||||
|
@ -21042,46 +21040,44 @@ void BfExprEvaluator::Visit(BfIndexerExpression* indexerExpr)
|
||||||
|
|
||||||
methodMatcher.mCheckedKind = checkedKind;
|
methodMatcher.mCheckedKind = checkedKind;
|
||||||
methodMatcher.mTarget = target;
|
methodMatcher.mTarget = target;
|
||||||
methodMatcher.CheckMethod(startCheckTypeInst, curCheckType, checkMethod, false);
|
bool hadMatch = methodMatcher.CheckMethod(startCheckTypeInst, curCheckType, checkMethod, false);
|
||||||
|
|
||||||
if ((methodMatcher.mBestMethodDef == checkMethod) || (methodMatcher.mBackupMethodDef == checkMethod))
|
if ((hadMatch) || (methodMatcher.mBackupMethodDef == checkMethod))
|
||||||
{
|
{
|
||||||
foundPropTypeInst = curCheckType;
|
foundPropTypeInst = curCheckType;
|
||||||
foundProp = prop;
|
foundProp = prop;
|
||||||
matchedIndexCount = (int)checkMethod->mParams.size();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foundProp != NULL)
|
|
||||||
{
|
|
||||||
|
|
||||||
mPropSrc = indexerExpr->mOpenBracket;
|
|
||||||
mPropDef = foundProp;
|
|
||||||
if (foundProp->mIsStatic)
|
|
||||||
{
|
|
||||||
mPropTarget = BfTypedValue(curCheckType);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (target.mType != foundPropTypeInst)
|
|
||||||
mPropTarget = mModule->Cast(indexerExpr->mTarget, target, foundPropTypeInst);
|
|
||||||
else
|
|
||||||
mPropTarget = target;
|
|
||||||
}
|
|
||||||
mOrigPropTarget = mPropTarget;
|
|
||||||
if (isInlined)
|
|
||||||
mPropGetMethodFlags = (BfGetMethodInstanceFlags)(mPropGetMethodFlags | BfGetMethodInstanceFlag_ForceInline);
|
|
||||||
mPropCheckedKind = checkedKind;
|
|
||||||
|
|
||||||
if ((target.IsBase()) && (mPropDef->IsVirtual()))
|
|
||||||
mPropDefBypassVirtual = true;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
curCheckType = curCheckType->mBaseType;
|
curCheckType = curCheckType->mBaseType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (foundProp != NULL)
|
||||||
|
{
|
||||||
|
mPropSrc = indexerExpr->mOpenBracket;
|
||||||
|
mPropDef = foundProp;
|
||||||
|
if (foundProp->mIsStatic)
|
||||||
|
{
|
||||||
|
mPropTarget = BfTypedValue(curCheckType);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (target.mType != foundPropTypeInst)
|
||||||
|
mPropTarget = mModule->Cast(indexerExpr->mTarget, target, foundPropTypeInst);
|
||||||
|
else
|
||||||
|
mPropTarget = target;
|
||||||
|
}
|
||||||
|
mOrigPropTarget = mPropTarget;
|
||||||
|
if (isInlined)
|
||||||
|
mPropGetMethodFlags = (BfGetMethodInstanceFlags)(mPropGetMethodFlags | BfGetMethodInstanceFlag_ForceInline);
|
||||||
|
mPropCheckedKind = checkedKind;
|
||||||
|
|
||||||
|
if ((target.IsBase()) && (mPropDef->IsVirtual()))
|
||||||
|
mPropDefBypassVirtual = true;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mModule->Fail("Unable to find indexer property", indexerExpr->mTarget);
|
mModule->Fail("Unable to find indexer property", indexerExpr->mTarget);
|
||||||
|
|
|
@ -76,6 +76,17 @@ namespace Tests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Foo
|
||||||
|
{
|
||||||
|
public virtual int this[int i] => i;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Bar : Foo
|
||||||
|
{
|
||||||
|
public override int this[int i] => i*i;
|
||||||
|
public Span<int> this[Range r] => default;
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public static void TestBasics()
|
public static void TestBasics()
|
||||||
{
|
{
|
||||||
|
@ -102,6 +113,9 @@ namespace Tests
|
||||||
int a = sa[3, 4, 5];
|
int a = sa[3, 4, 5];
|
||||||
Test.Assert(a == 12);
|
Test.Assert(a == 12);
|
||||||
Test.Assert(sa.mA == 9024);
|
Test.Assert(sa.mA == 9024);
|
||||||
|
|
||||||
|
Bar bar = scope .();
|
||||||
|
Test.Assert(bar[3] == 9);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue