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,25 +5541,41 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, BfMethodInstance*
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CeEvalFlags evalFlags = CeEvalFlags_None;
|
bool hasUndef = false;
|
||||||
if ((mBfEvalExprFlags & BfEvalExprFlags_NoCeRebuildFlags) != 0)
|
for (auto arg : irArgs)
|
||||||
evalFlags = (CeEvalFlags)(evalFlags | CeEvalFlags_NoRebuild);
|
|
||||||
auto constRet = mModule->mCompiler->mCEMachine->Call(targetSrc, mModule, methodInstance, irArgs, evalFlags, mExpectingType);
|
|
||||||
if (constRet)
|
|
||||||
{
|
{
|
||||||
auto constant = mModule->mBfIRBuilder->GetConstant(constRet.mValue);
|
auto constant = mModule->mBfIRBuilder->GetConstant(arg);
|
||||||
BF_ASSERT(!constRet.mType->IsVar());
|
if (constant == NULL)
|
||||||
return constRet;
|
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
|
auto constant = mModule->mBfIRBuilder->GetConstant(constRet.mValue);
|
||||||
mModule->DeferRebuildType(mModule->mCurTypeInstance);
|
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;
|
doConstReturn = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12506,7 +12522,7 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam
|
||||||
{
|
{
|
||||||
if ((mModule->mCurMethodState != NULL) && (mModule->mCurMethodState->mClosureState != NULL) && (mModule->mCurMethodState->mClosureState->mCapturing))
|
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);
|
VisitLambdaBodies(lambdaBindExpr->mBody, lambdaBindExpr->mDtor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4074,7 +4074,10 @@ BfIRValue BfIRBuilder::CreateNumericCast(BfIRValue val, bool valIsSigned, BfType
|
||||||
FixTypeCode(typeCode);
|
FixTypeCode(typeCode);
|
||||||
if (val.IsConst())
|
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)
|
if (constVal->mTypeCode < BfTypeCode_Length)
|
||||||
{
|
{
|
||||||
// ? -> Int
|
// ? -> Int
|
||||||
|
|
|
@ -2608,6 +2608,9 @@ void BfModule::DoPopulateType_TypeAlias(BfTypeInstance* typeAlias)
|
||||||
|
|
||||||
if (typeAlias->mBaseType == NULL)
|
if (typeAlias->mBaseType == NULL)
|
||||||
typeAlias->mBaseType = ResolveTypeDef(mCompiler->mValueTypeTypeDef)->ToTypeInstance();
|
typeAlias->mBaseType = ResolveTypeDef(mCompiler->mValueTypeTypeDef)->ToTypeInstance();
|
||||||
|
|
||||||
|
if ((typeAlias->mGenericTypeInfo != NULL) && (!typeAlias->mGenericTypeInfo->mFinishedGenericParams))
|
||||||
|
FinishGenericParams(typeAlias);
|
||||||
|
|
||||||
typeAlias->mDefineState = BfTypeDefineState_ResolvingBaseType;
|
typeAlias->mDefineState = BfTypeDefineState_ResolvingBaseType;
|
||||||
BfTypeState typeState(mCurTypeInstance, mContext->mCurTypeState);
|
BfTypeState typeState(mCurTypeInstance, mContext->mCurTypeState);
|
||||||
|
@ -2670,7 +2673,9 @@ void BfModule::DoPopulateType_TypeAlias(BfTypeInstance* typeAlias)
|
||||||
typeAlias->mCustomAttributes = GetCustomAttributes(typeDef->mTypeDeclaration->mAttributes, BfAttributeTargets_Alias);
|
typeAlias->mCustomAttributes = GetCustomAttributes(typeDef->mTypeDeclaration->mAttributes, BfAttributeTargets_Alias);
|
||||||
|
|
||||||
if (typeAlias->mGenericTypeInfo != NULL)
|
if (typeAlias->mGenericTypeInfo != NULL)
|
||||||
DoPopulateType_SetGenericDependencies(typeAlias);
|
{
|
||||||
|
DoPopulateType_SetGenericDependencies(typeAlias);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BfModule::DoPopulateType_FinishEnum(BfTypeInstance* typeInstance, bool underlyingTypeDeferred, HashContext* dataMemberHashCtx, BfType* unionInnerType)
|
void BfModule::DoPopulateType_FinishEnum(BfTypeInstance* typeInstance, bool underlyingTypeDeferred, HashContext* dataMemberHashCtx, BfType* unionInnerType)
|
||||||
|
|
|
@ -265,7 +265,19 @@ namespace Tests
|
||||||
const String cTest0 = Compiler.ReadText("Test0.txt");
|
const String cTest0 = Compiler.ReadText("Test0.txt");
|
||||||
const String cTest1 = new String('A', 12);
|
const String cTest1 = new String('A', 12);
|
||||||
const uint8[?] cTest0Binary = Compiler.ReadBinary("Test0.txt");
|
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]
|
[Test]
|
||||||
public static void TestBasics()
|
public static void TestBasics()
|
||||||
{
|
{
|
||||||
|
@ -311,6 +323,10 @@ namespace Tests
|
||||||
Test.Assert(cTest1 == "AAAAAAAAAAAA");
|
Test.Assert(cTest1 == "AAAAAAAAAAAA");
|
||||||
Test.Assert((Object)cTest1 == (Object)"AAAAAAAAAAAA");
|
Test.Assert((Object)cTest1 == (Object)"AAAAAAAAAAAA");
|
||||||
Test.Assert((cTest0Binary[0] == (.)'T') && ((cTest0Binary.Count == 6) || (cTest0Binary.Count == 7)));
|
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