From 0803faf5961b49be168c933d64089bffaa4d488f Mon Sep 17 00:00:00 2001 From: ZZYZX Date: Thu, 16 Feb 2017 04:22:14 +0200 Subject: [PATCH] Compile time check for abstract class instantiation to reduce programming errors ASAP --- src/scripting/backend/codegen.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index 77ac9498c9..1f2b038f17 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -5058,6 +5058,13 @@ FxExpression *FxNew::Resolve(FCompileContext &ctx) if (val->isConstant()) { auto cls = static_cast(static_cast(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); }