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:
parent
f35a3de175
commit
249f4f1016
4 changed files with 58 additions and 18 deletions
|
@ -5541,23 +5541,39 @@ 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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,7 +2673,9 @@ 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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue