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

Fix indexing generic params

This commit is contained in:
Brian Fiete 2024-11-02 07:35:05 -04:00
parent 56c41ba302
commit c53ef1c346
2 changed files with 47 additions and 10 deletions

View file

@ -21944,8 +21944,12 @@ void BfExprEvaluator::HandleIndexerExpression(BfIndexerExpression* indexerExpr,
return; return;
} }
if (target.mType->IsTypeInstance()) if ((target.mType->IsTypeInstance()) || (target.mType->IsGenericParam()))
{ {
BfGenericParamInstance* genericParamInstance = NULL;
if (target.mType->IsGenericParam())
genericParamInstance = mModule->GetGenericParamInstance((BfGenericParamType*)target.mType);
mIndexerValues.clear(); mIndexerValues.clear();
SizedArray<BfExpression*, 2> argExprs; SizedArray<BfExpression*, 2> argExprs;
@ -21969,9 +21973,15 @@ void BfExprEvaluator::HandleIndexerExpression(BfIndexerExpression* indexerExpr,
BfPropertyDef* foundProp = NULL; BfPropertyDef* foundProp = NULL;
BfTypeInstance* foundPropTypeInst = NULL; BfTypeInstance* foundPropTypeInst = NULL;
auto curCheckType = startCheckTypeInst; BfBaseClassWalker baseClassWalker(target.mType, NULL, mModule);
while (curCheckType != NULL)
while (true)
{ {
auto checkEntry = baseClassWalker.Next();
auto curCheckType = checkEntry.mTypeInstance;
if (curCheckType == NULL)
break;
BfProtectionCheckFlags protectionCheckFlags = BfProtectionCheckFlag_None; BfProtectionCheckFlags protectionCheckFlags = BfProtectionCheckFlag_None;
curCheckType->mTypeDef->PopulateMemberSets(); curCheckType->mTypeDef->PopulateMemberSets();
@ -21993,9 +22003,6 @@ void BfExprEvaluator::HandleIndexerExpression(BfIndexerExpression* indexerExpr,
if (checkMethod->mMethodType != BfMethodType_PropertyGetter) if (checkMethod->mMethodType != BfMethodType_PropertyGetter)
continue; continue;
// For generic params - check interface constraints for an indexer, call that method
BF_ASSERT(!target.mType->IsGenericParam());
if (checkMethod->mIsStatic != wantStatic) if (checkMethod->mIsStatic != wantStatic)
continue; continue;
@ -22073,7 +22080,6 @@ void BfExprEvaluator::HandleIndexerExpression(BfIndexerExpression* indexerExpr,
if (checkedKind == BfCheckedKind_NotSet) if (checkedKind == BfCheckedKind_NotSet)
wantsChecks = mModule->GetDefaultCheckedKind() == BfCheckedKind_Checked; wantsChecks = mModule->GetDefaultCheckedKind() == BfCheckedKind_Checked;
//target.mType = mModule->ResolveGenericType(target.mType);
if (target.mType->IsVar()) if (target.mType->IsVar())
{ {
mResult = target; mResult = target;

View file

@ -1,4 +1,10 @@
using System; using System;
using System.Collections;
public interface IIndexable<T>
{
T this[int index] { get; set; }
}
namespace Tests namespace Tests
{ {
@ -87,6 +93,28 @@ namespace Tests
public Span<int> this[Range r] => default; public Span<int> this[Range r] => default;
} }
class IndexTest : IIndexable<float>
{
public float this[int index]
{
get
{
return index;
}
set
{
}
}
}
public static float Get<T>(T indexable) where T : IIndexable<float>
{
float f = indexable[4];
return f;
}
[Test] [Test]
public static void TestBasics() public static void TestBasics()
{ {
@ -116,6 +144,9 @@ namespace Tests
Bar bar = scope .(); Bar bar = scope .();
Test.Assert(bar[3] == 9); Test.Assert(bar[3] == 9);
IndexTest it = scope .();
Test.Assert(it[5] == 5.0f);
} }
} }
} }