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;
|
||||
|
||||
BfPropertyDef* foundProp = NULL;
|
||||
BfTypeInstance* foundPropTypeInst = NULL;
|
||||
|
||||
auto curCheckType = startCheckTypeInst;
|
||||
while (curCheckType != NULL)
|
||||
{
|
||||
BfProtectionCheckFlags protectionCheckFlags = BfProtectionCheckFlag_None;
|
||||
|
||||
BfPropertyDef* foundProp = NULL;
|
||||
BfTypeInstance* foundPropTypeInst = NULL;
|
||||
|
||||
int matchedIndexCount = 0;
|
||||
|
||||
curCheckType->mTypeDef->PopulateMemberSets();
|
||||
|
||||
BfMemberSetEntry* entry;
|
||||
|
@ -21042,20 +21040,21 @@ void BfExprEvaluator::Visit(BfIndexerExpression* indexerExpr)
|
|||
|
||||
methodMatcher.mCheckedKind = checkedKind;
|
||||
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;
|
||||
foundProp = prop;
|
||||
matchedIndexCount = (int)checkMethod->mParams.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
curCheckType = curCheckType->mBaseType;
|
||||
}
|
||||
|
||||
if (foundProp != NULL)
|
||||
{
|
||||
|
||||
mPropSrc = indexerExpr->mOpenBracket;
|
||||
mPropDef = foundProp;
|
||||
if (foundProp->mIsStatic)
|
||||
|
@ -21079,9 +21078,6 @@ void BfExprEvaluator::Visit(BfIndexerExpression* indexerExpr)
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
curCheckType = curCheckType->mBaseType;
|
||||
}
|
||||
}
|
||||
|
||||
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]
|
||||
public static void TestBasics()
|
||||
{
|
||||
|
@ -102,6 +113,9 @@ namespace Tests
|
|||
int a = sa[3, 4, 5];
|
||||
Test.Assert(a == 12);
|
||||
Test.Assert(sa.mA == 9024);
|
||||
|
||||
Bar bar = scope .();
|
||||
Test.Assert(bar[3] == 9);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue