1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

undef instead of fakeVal in const variation, fix typeAlias generic

This commit is contained in:
Brian Fiete 2022-01-22 06:45:10 -05:00
parent bc39fe6204
commit f4aa6c26ff
2 changed files with 21 additions and 13 deletions

View file

@ -9389,11 +9389,11 @@ BfTypedValue BfModule::TryLookupGenericConstVaue(BfIdentifierNode* identifierNod
if (contextTypeInstance->IsBoxed())
genericCheckTypeInstance = contextTypeInstance->GetUnderlyingType()->ToTypeInstance();
bool doFakeVal = false;
bool doUndefVal = false;
if (genericCheckTypeInstance->IsUnspecializedTypeVariation())
{
genericCheckTypeInstance = GetUnspecializedTypeInstance(genericCheckTypeInstance);
doFakeVal = true;
doUndefVal = true;
}
BfGenericParamDef* genericParamDef = NULL;
@ -9497,9 +9497,9 @@ BfTypedValue BfModule::TryLookupGenericConstVaue(BfIdentifierNode* identifierNod
}
else if (genericParamResult->IsGenericParam())
{
if ((doFakeVal) && (genericTypeConstraint != NULL))
if ((doUndefVal) && (genericTypeConstraint != NULL))
{
return BfTypedValue(mBfIRBuilder->GetFakeVal(), genericTypeConstraint);
return GetDefaultTypedValue(genericTypeConstraint, false, BfDefaultValueKind_Undef);
}
if (((genericParamDef->mGenericParamFlags | origGenericParamDef->mGenericParamFlags) & BfGenericParamFlag_Const) != 0)
@ -10649,11 +10649,11 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
genericTypeInst->mTypeDef = typeDef;
if ((commonOuterType != NULL) && (outerTypeInstance->IsGenericTypeInstance()))
auto parentTypeInstance = outerTypeInstance;
if ((parentTypeInstance != NULL) && (parentTypeInstance->IsTypeAlias()))
parentTypeInstance = (BfTypeInstance*)GetOuterType(parentTypeInstance)->ToTypeInstance();
if ((parentTypeInstance != NULL) && (parentTypeInstance->IsGenericTypeInstance()))
{
auto parentTypeInstance = outerTypeInstance;
if (parentTypeInstance->IsTypeAlias())
parentTypeInstance = (BfTypeInstance*)GetOuterType(parentTypeInstance)->ToTypeInstance();
genericTypeInst->mGenericTypeInfo->mMaxGenericDepth = BF_MAX(genericTypeInst->mGenericTypeInfo->mMaxGenericDepth, parentTypeInstance->mGenericTypeInfo->mMaxGenericDepth);
for (int i = 0; i < startDefGenericParamIdx; i++)
{
@ -10661,7 +10661,6 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
genericTypeInst->mGenericTypeInfo->mTypeGenericArguments.push_back(parentTypeInstance->mGenericTypeInfo->mTypeGenericArguments[i]);
auto typeGenericArg = genericTypeInst->mGenericTypeInfo->mTypeGenericArguments[i];
genericTypeInst->mGenericTypeInfo->mIsUnspecialized |= typeGenericArg->IsGenericParam() || typeGenericArg->IsUnspecializedType();
}
}

View file

@ -105,6 +105,13 @@ namespace Tests
}
typealias BigNum<N> = BigNum<N,const 0>;
public struct BigNum<ArgN, ExponentCells> where ArgN : const int where ExponentCells : const int64
{
static int CalculateN() => Math.Max(1,(int)ArgN);
public const int N = CalculateN();
}
[Test]
public static void TestBasics()
{
@ -117,6 +124,8 @@ namespace Tests
Test.Assert(iList.SequenceEquals(iSpan));
iList.Add(4);
Test.Assert(!iList.SequenceEquals(iSpan));
Test.Assert(BigNum<const 3>.N == 3);
}
}
}