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

Fixed some const constraint undef issues

This commit is contained in:
Brian Fiete 2021-12-31 13:51:08 -05:00
parent f35a3de175
commit 249f4f1016
4 changed files with 58 additions and 18 deletions

View file

@ -5540,6 +5540,21 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, BfMethodInstance*
// This could only really be the case for a Type, since no other 'this' could qualify as const
}
else
{
bool hasUndef = false;
for (auto arg : irArgs)
{
auto constant = mModule->mBfIRBuilder->GetConstant(arg);
if (constant == NULL)
continue;
if (constant->mConstType == BfConstType_Undef)
{
hasUndef = true;
break;
}
}
if (!hasUndef)
{
CeEvalFlags evalFlags = CeEvalFlags_None;
if ((mBfEvalExprFlags & BfEvalExprFlags_NoCeRebuildFlags) != 0)
@ -5560,6 +5575,7 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, BfMethodInstance*
mModule->DeferRebuildType(mModule->mCurTypeInstance);
}
}
}
doConstReturn = true;
}
}

View file

@ -4075,6 +4075,9 @@ BfIRValue BfIRBuilder::CreateNumericCast(BfIRValue val, bool valIsSigned, BfType
if (val.IsConst())
{
auto constVal = GetConstantById(val.mId);
if (constVal->mConstType == BfConstType_Undef)
return GetUndefConstValue(GetPrimitiveType(typeCode));
if (constVal->mTypeCode < BfTypeCode_Length)
{
// ? -> Int

View file

@ -2609,6 +2609,9 @@ void BfModule::DoPopulateType_TypeAlias(BfTypeInstance* typeAlias)
if (typeAlias->mBaseType == NULL)
typeAlias->mBaseType = ResolveTypeDef(mCompiler->mValueTypeTypeDef)->ToTypeInstance();
if ((typeAlias->mGenericTypeInfo != NULL) && (!typeAlias->mGenericTypeInfo->mFinishedGenericParams))
FinishGenericParams(typeAlias);
typeAlias->mDefineState = BfTypeDefineState_ResolvingBaseType;
BfTypeState typeState(mCurTypeInstance, mContext->mCurTypeState);
typeState.mPopulateType = BfPopulateType_Data;
@ -2670,8 +2673,10 @@ void BfModule::DoPopulateType_TypeAlias(BfTypeInstance* typeAlias)
typeAlias->mCustomAttributes = GetCustomAttributes(typeDef->mTypeDeclaration->mAttributes, BfAttributeTargets_Alias);
if (typeAlias->mGenericTypeInfo != NULL)
{
DoPopulateType_SetGenericDependencies(typeAlias);
}
}
void BfModule::DoPopulateType_FinishEnum(BfTypeInstance* typeInstance, bool underlyingTypeDeferred, HashContext* dataMemberHashCtx, BfType* unionInnerType)
{

View file

@ -266,6 +266,18 @@ namespace Tests
const String cTest1 = new String('A', 12);
const uint8[?] cTest0Binary = Compiler.ReadBinary("Test0.txt");
class ClassB<T> where T : const int
{
public typealias TA = comptype(GetVal(10, T));
public const int cTimesTen = 10 * T;
[Comptime]
static Type GetVal(int a, int b)
{
return typeof(float);
}
}
[Test]
public static void TestBasics()
{
@ -311,6 +323,10 @@ namespace Tests
Test.Assert(cTest1 == "AAAAAAAAAAAA");
Test.Assert((Object)cTest1 == (Object)"AAAAAAAAAAAA");
Test.Assert((cTest0Binary[0] == (.)'T') && ((cTest0Binary.Count == 6) || (cTest0Binary.Count == 7)));
ClassB<const 3>.TA f = default;
Test.Assert(typeof(decltype(f)) == typeof(float));
Test.Assert(ClassB<const 3>.cTimesTen == 30);
}
}
}