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

Fixed explicit interface indexer

This commit is contained in:
Brian Fiete 2024-11-20 14:05:42 -05:00
parent 908a76b92a
commit 295057b026
2 changed files with 32 additions and 1 deletions

View file

@ -21931,6 +21931,10 @@ void BfExprEvaluator::Visit(BfIndexerExpression* indexerExpr)
void BfExprEvaluator::HandleIndexerExpression(BfIndexerExpression* indexerExpr, BfTypedValue target) void BfExprEvaluator::HandleIndexerExpression(BfIndexerExpression* indexerExpr, BfTypedValue target)
{ {
BfAstNode* refNode = indexerExpr->mOpenBracket;
if (refNode == NULL)
refNode = indexerExpr->mTarget;
bool wantStatic = false; bool wantStatic = false;
// Try first as a non-static indexer, then as a static indexer // Try first as a non-static indexer, then as a static indexer
@ -22028,6 +22032,13 @@ void BfExprEvaluator::HandleIndexerExpression(BfIndexerExpression* indexerExpr,
BfMethodDef* methodDef = NULL; BfMethodDef* methodDef = NULL;
auto startCheckTypeInst = target.mType->ToTypeInstance(); auto startCheckTypeInst = target.mType->ToTypeInstance();
auto lookupType = target.mType;
if (lookupType != NULL)
{
lookupType = BindGenericType(refNode, lookupType);
if (lookupType->IsGenericParam())
startCheckTypeInst = NULL;
}
for (int pass = 0; pass < 2; pass++) for (int pass = 0; pass < 2; pass++)
{ {
@ -22036,7 +22047,7 @@ void BfExprEvaluator::HandleIndexerExpression(BfIndexerExpression* indexerExpr,
BfPropertyDef* foundProp = NULL; BfPropertyDef* foundProp = NULL;
BfTypeInstance* foundPropTypeInst = NULL; BfTypeInstance* foundPropTypeInst = NULL;
BfBaseClassWalker baseClassWalker(target.mType, NULL, mModule, true); BfBaseClassWalker baseClassWalker(lookupType, NULL, mModule, true);
while (true) while (true)
{ {

View file

@ -109,6 +109,22 @@ namespace Tests
} }
} }
class IndexTestExplicit : IIndexable<float>
{
public float IIndexable<float>.this[int index]
{
get
{
return index;
}
set
{
}
}
}
public static float Get<T>(T indexable) where T : IIndexable<float> public static float Get<T>(T indexable) where T : IIndexable<float>
{ {
float f = indexable[4]; float f = indexable[4];
@ -147,6 +163,10 @@ namespace Tests
IndexTest it = scope .(); IndexTest it = scope .();
Test.Assert(it[5] == 5.0f); Test.Assert(it[5] == 5.0f);
Test.Assert(Get(it) == 4);
IndexTestExplicit it2 = scope .();
Test.Assert(Get(it2) == 4);
} }
} }
} }