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

Improved errors for generic instantiation

This commit is contained in:
Brian Fiete 2020-09-21 07:59:33 -07:00
parent 2d4cc6d86e
commit da563ee14b

View file

@ -6744,21 +6744,27 @@ bool BfExprEvaluator::CheckGenericCtor(BfGenericParamType* genericParamType, BfR
auto genericConstraint = mModule->GetGenericParamInstance(genericParamType);
bool success = true;
if ((genericConstraint->mGenericParamFlags & BfGenericParamFlag_New) == 0)
{
mModule->Fail(StrFormat("Must add 'where %s : new' constraint to generic parameter to instantiate type", genericConstraint->GetGenericParamDef()->mName.c_str()), targetSrc);
success = false;
}
if ((genericConstraint->mGenericParamFlags & BfGenericParamFlag_Struct) == 0)
{
mModule->Fail(StrFormat("Must add 'where %s : struct' constraint to generic parameter to instantiate type without allocator", genericConstraint->GetGenericParamDef()->mName.c_str()), targetSrc);
success = false;
}
if ((argValues.mArguments != NULL) && (argValues.mArguments->size() != 0))
{
mModule->Fail(StrFormat("Only default parameterless constructors can be called on generic argument '%s'", genericConstraint->GetGenericParamDef()->mName.c_str()), targetSrc);
success = false;
}
else if ((genericConstraint->mGenericParamFlags & (BfGenericParamFlag_New | BfGenericParamFlag_Struct)) == 0)
{
mModule->Fail(StrFormat("Must add 'where %s : new, struct' constraint to generic parameter to instantiate type", genericConstraint->GetGenericParamDef()->mName.c_str()), targetSrc);
success = false;
}
else if ((genericConstraint->mGenericParamFlags & BfGenericParamFlag_New) == 0)
{
mModule->Fail(StrFormat("Must add 'where %s : new' constraint to generic parameter to instantiate type", genericConstraint->GetGenericParamDef()->mName.c_str()), targetSrc);
success = false;
}
else if ((genericConstraint->mGenericParamFlags & BfGenericParamFlag_Struct) == 0)
{
mModule->Fail(StrFormat("Must add 'where %s : struct' constraint to generic parameter to instantiate type without allocator", genericConstraint->GetGenericParamDef()->mName.c_str()), targetSrc);
success = false;
}
return success;
}