mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-14 14:24:10 +02:00
Deeper binop interface check for generic param
This commit is contained in:
parent
f8da7eb618
commit
bf3dec931a
3 changed files with 44 additions and 0 deletions
|
@ -69,11 +69,21 @@ BfBaseClassWalker::BfBaseClassWalker(BfType* typeA, BfType* typeB, BfModule* mod
|
||||||
AddConstraints(typeA, module->GetGenericParamInstance((BfGenericParamType*)typeA));
|
AddConstraints(typeA, module->GetGenericParamInstance((BfGenericParamType*)typeA));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((typeA != NULL) && (typeA->IsInterface()))
|
||||||
|
{
|
||||||
|
AddInterfaces(typeA, typeA->ToTypeInstance());
|
||||||
|
}
|
||||||
|
|
||||||
if ((typeB != NULL) && (typeB->IsGenericParam()))
|
if ((typeB != NULL) && (typeB->IsGenericParam()))
|
||||||
{
|
{
|
||||||
mMayBeFromInterface = true;
|
mMayBeFromInterface = true;
|
||||||
AddConstraints(typeB, module->GetGenericParamInstance((BfGenericParamType*)typeB));
|
AddConstraints(typeB, module->GetGenericParamInstance((BfGenericParamType*)typeB));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((typeB != NULL) && (typeB->IsInterface()))
|
||||||
|
{
|
||||||
|
AddInterfaces(typeB, typeB->ToTypeInstance());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*BfBaseClassWalker::BfBaseClassWalker(BfTypeInstance* typeA, BfTypeInstance* typeB)
|
/*BfBaseClassWalker::BfBaseClassWalker(BfTypeInstance* typeA, BfTypeInstance* typeB)
|
||||||
|
@ -95,6 +105,8 @@ void BfBaseClassWalker::AddConstraints(BfType* srcType, BfGenericParamInstance*
|
||||||
{
|
{
|
||||||
auto typeInst = genericParam->mTypeConstraint->ToTypeInstance();
|
auto typeInst = genericParam->mTypeConstraint->ToTypeInstance();
|
||||||
{
|
{
|
||||||
|
if (typeInst->IsInterface())
|
||||||
|
AddInterfaces(srcType, typeInst->ToTypeInstance());
|
||||||
Entry entry(srcType, typeInst);
|
Entry entry(srcType, typeInst);
|
||||||
if ((typeInst != NULL) && (!mManualList.Contains(entry)))
|
if ((typeInst != NULL) && (!mManualList.Contains(entry)))
|
||||||
mManualList.Add(entry);
|
mManualList.Add(entry);
|
||||||
|
@ -103,12 +115,24 @@ void BfBaseClassWalker::AddConstraints(BfType* srcType, BfGenericParamInstance*
|
||||||
|
|
||||||
for (auto typeInst : genericParam->mInterfaceConstraints)
|
for (auto typeInst : genericParam->mInterfaceConstraints)
|
||||||
{
|
{
|
||||||
|
if (typeInst->IsInterface())
|
||||||
|
AddInterfaces(srcType, typeInst->ToTypeInstance());
|
||||||
Entry entry(srcType, typeInst);
|
Entry entry(srcType, typeInst);
|
||||||
if ((typeInst != NULL) && (!mManualList.Contains(entry)))
|
if ((typeInst != NULL) && (!mManualList.Contains(entry)))
|
||||||
mManualList.Add(entry);
|
mManualList.Add(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BfBaseClassWalker::AddInterfaces(BfType* srcType, BfTypeInstance* typeInst)
|
||||||
|
{
|
||||||
|
for (auto ifaceEntry : typeInst->mInterfaces)
|
||||||
|
{
|
||||||
|
Entry entry(srcType, ifaceEntry.mInterfaceType);
|
||||||
|
if ((typeInst != NULL) && (!mManualList.Contains(entry)))
|
||||||
|
mManualList.Add(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BfBaseClassWalker::Entry BfBaseClassWalker::Next()
|
BfBaseClassWalker::Entry BfBaseClassWalker::Next()
|
||||||
{
|
{
|
||||||
if (!mManualList.IsEmpty())
|
if (!mManualList.IsEmpty())
|
||||||
|
|
|
@ -313,6 +313,7 @@ public:
|
||||||
BfBaseClassWalker();
|
BfBaseClassWalker();
|
||||||
BfBaseClassWalker(BfType* typeA, BfType* typeB, BfModule* module);
|
BfBaseClassWalker(BfType* typeA, BfType* typeB, BfModule* module);
|
||||||
void AddConstraints(BfType* srcType, BfGenericParamInstance* genericParam);
|
void AddConstraints(BfType* srcType, BfGenericParamInstance* genericParam);
|
||||||
|
void AddInterfaces(BfType* srcType, BfTypeInstance* typeInst);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Entry Next();
|
Entry Next();
|
||||||
|
|
|
@ -413,6 +413,25 @@ namespace Tests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface IAdd
|
||||||
|
{
|
||||||
|
static Self operator+(Self a, Self b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IAdd2 : IAdd
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void MyFunction<T>(T a, T b) where T : IAdd
|
||||||
|
{
|
||||||
|
T sum = a + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void MyFunction2<T>(T a, T b) where T : IAdd2
|
||||||
|
{
|
||||||
|
T sum = a + b;
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public static void TestDefaults()
|
public static void TestDefaults()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue