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

@ -5541,25 +5541,41 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, BfMethodInstance*
}
else
{
CeEvalFlags evalFlags = CeEvalFlags_None;
if ((mBfEvalExprFlags & BfEvalExprFlags_NoCeRebuildFlags) != 0)
evalFlags = (CeEvalFlags)(evalFlags | CeEvalFlags_NoRebuild);
auto constRet = mModule->mCompiler->mCEMachine->Call(targetSrc, mModule, methodInstance, irArgs, evalFlags, mExpectingType);
if (constRet)
bool hasUndef = false;
for (auto arg : irArgs)
{
auto constant = mModule->mBfIRBuilder->GetConstant(constRet.mValue);
BF_ASSERT(!constRet.mType->IsVar());
return constRet;
auto constant = mModule->mBfIRBuilder->GetConstant(arg);
if (constant == NULL)
continue;
if (constant->mConstType == BfConstType_Undef)
{
hasUndef = true;
break;
}
}
if (mModule->mCompiler->mFastFinish)
if (!hasUndef)
{
if ((mModule->mCurMethodInstance == NULL) || (!mModule->mCurMethodInstance->mIsAutocompleteMethod))
CeEvalFlags evalFlags = CeEvalFlags_None;
if ((mBfEvalExprFlags & BfEvalExprFlags_NoCeRebuildFlags) != 0)
evalFlags = (CeEvalFlags)(evalFlags | CeEvalFlags_NoRebuild);
auto constRet = mModule->mCompiler->mCEMachine->Call(targetSrc, mModule, methodInstance, irArgs, evalFlags, mExpectingType);
if (constRet)
{
// We didn't properly resolve this so queue for a rebuild later
mModule->DeferRebuildType(mModule->mCurTypeInstance);
}
}
auto constant = mModule->mBfIRBuilder->GetConstant(constRet.mValue);
BF_ASSERT(!constRet.mType->IsVar());
return constRet;
}
if (mModule->mCompiler->mFastFinish)
{
if ((mModule->mCurMethodInstance == NULL) || (!mModule->mCurMethodInstance->mIsAutocompleteMethod))
{
// We didn't properly resolve this so queue for a rebuild later
mModule->DeferRebuildType(mModule->mCurTypeInstance);
}
}
}
doConstReturn = true;
}
}
@ -12506,7 +12522,7 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam
{
if ((mModule->mCurMethodState != NULL) && (mModule->mCurMethodState->mClosureState != NULL) && (mModule->mCurMethodState->mClosureState->mCapturing))
{
SetAndRestoreValue<bool> prevIgnoreErrors(mModule->mIgnoreErrors, true);
SetAndRestoreValue<bool> prevIgnoreErrors(mModule->mIgnoreErrors, true);
VisitLambdaBodies(lambdaBindExpr->mBody, lambdaBindExpr->mDtor);
}

View file

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

View file

@ -2608,6 +2608,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);
@ -2670,7 +2673,9 @@ void BfModule::DoPopulateType_TypeAlias(BfTypeInstance* typeAlias)
typeAlias->mCustomAttributes = GetCustomAttributes(typeDef->mTypeDeclaration->mAttributes, BfAttributeTargets_Alias);
if (typeAlias->mGenericTypeInfo != NULL)
DoPopulateType_SetGenericDependencies(typeAlias);
{
DoPopulateType_SetGenericDependencies(typeAlias);
}
}
void BfModule::DoPopulateType_FinishEnum(BfTypeInstance* typeInstance, bool underlyingTypeDeferred, HashContext* dataMemberHashCtx, BfType* unionInnerType)

View file

@ -265,7 +265,19 @@ namespace Tests
const String cTest0 = Compiler.ReadText("Test0.txt");
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);
}
}
}