Compile time check for abstract class instantiation to reduce programming errors ASAP

This commit is contained in:
ZZYZX 2017-02-16 04:22:14 +02:00
parent 0819dd8d89
commit 0803faf596

View file

@ -5058,6 +5058,13 @@ FxExpression *FxNew::Resolve(FCompileContext &ctx)
if (val->isConstant())
{
auto cls = static_cast<PClass *>(static_cast<FxConstant*>(val)->GetValue().GetPointer());
if ((cls->ObjectFlags & OF_Abstract) && cls != ctx.Class)
{
ScriptPosition.Message(MSG_ERROR, "Cannot instantiate abstract class %s outside of that class", cls->TypeName.GetChars());
delete this;
return nullptr;
}
ValueType = NewPointer(cls);
}