diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index 551378d8bc..77ac9498c9 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -5023,7 +5023,7 @@ FxNew::FxNew(FxExpression *v) { val = new FxClassTypeCast(NewClassPointer(RUNTIME_CLASS(DObject)), v, false); ValueType = NewPointer(RUNTIME_CLASS(DObject)); - CallingClass = nullptr; + CallingFunction = nullptr; } //========================================================================== @@ -5048,7 +5048,7 @@ FxExpression *FxNew::Resolve(FCompileContext &ctx) CHECKRESOLVED(); SAFE_RESOLVE(val, ctx); - CallingClass = (PClass*)ctx.Class; + CallingFunction = ctx.Function; if (!val->ValueType->IsKindOf(RUNTIME_CLASS(PClassPointer))) { ScriptPosition.Message(MSG_ERROR, "Class type expected"); @@ -5075,7 +5075,7 @@ ExpEmit FxNew::Emit(VMFunctionBuilder *build) ExpEmit from = val->Emit(build); from.Free(build); ExpEmit to(build, REGT_POINTER); - build->Emit(from.Konst ? OP_NEW_K : OP_NEW, to.RegNum, from.RegNum, build->GetConstantAddress(CallingClass, ATAG_OBJECT)); + build->Emit(from.Konst ? OP_NEW_K : OP_NEW, to.RegNum, from.RegNum, build->GetConstantAddress(CallingFunction, ATAG_OBJECT)); return to; } diff --git a/src/scripting/backend/codegen.h b/src/scripting/backend/codegen.h index 90c4741706..3c43777168 100644 --- a/src/scripting/backend/codegen.h +++ b/src/scripting/backend/codegen.h @@ -1208,7 +1208,7 @@ private: class FxNew : public FxExpression { FxExpression *val; - PClass *CallingClass; + PFunction *CallingFunction; public: diff --git a/src/scripting/vm/vmexec.h b/src/scripting/vm/vmexec.h index 9f93af802e..01ad0111a6 100644 --- a/src/scripting/vm/vmexec.h +++ b/src/scripting/vm/vmexec.h @@ -787,8 +787,8 @@ begin: { b = B; PClass *cls = (PClass*)(pc->op == OP_NEW ? reg.a[b] : konsta[b].v); - PClass *callingcls = (PClass*)konsta[C].o; // [ZZ] due to how this is set, it's always const - if ((cls->ObjectFlags & OF_Abstract) && callingcls != cls) ThrowAbortException(X_OTHER, "Cannot instantiate abstract class %s outside of that class", cls->TypeName.GetChars()); + PFunction *callingfunc = (PFunction*)konsta[C].o; // [ZZ] due to how this is set, it's always const + if ((cls->ObjectFlags & OF_Abstract) && (!callingfunc || callingfunc->OwningClass != cls)) ThrowAbortException(X_OTHER, "Cannot instantiate abstract class %s outside of that class", cls->TypeName.GetChars()); reg.a[a] = cls->CreateNew(); reg.atag[a] = ATAG_OBJECT; NEXTOP;