diff --git a/src/scripting/codegeneration/codegen.cpp b/src/scripting/codegeneration/codegen.cpp index c7cd6e524..87f2e1f73 100644 --- a/src/scripting/codegeneration/codegen.cpp +++ b/src/scripting/codegeneration/codegen.cpp @@ -6199,9 +6199,9 @@ FxExpression *FxClassTypeCast::Resolve(FCompileContext &ctx) delete this; return x; } + auto to = static_cast(ValueType); if (basex->ValueType->GetClass() == RUNTIME_CLASS(PClassPointer)) { - auto to = static_cast(ValueType); auto from = static_cast(basex->ValueType); if (from->ClassRestriction->IsDescendantOf(to->ClassRestriction)) { @@ -6227,7 +6227,6 @@ FxExpression *FxClassTypeCast::Resolve(FCompileContext &ctx) { FName clsname = static_cast(basex)->GetValue().GetName(); PClass *cls = NULL; - FxExpression *x; if (clsname != NAME_None) { @@ -6250,12 +6249,8 @@ FxExpression *FxClassTypeCast::Resolve(FCompileContext &ctx) } ScriptPosition.Message(MSG_DEBUG, "resolving '%s' as class name", clsname.GetChars()); } - x = new FxConstant(cls, ScriptPosition); - } - else - { - x = new FxConstant(ScriptPosition); // create a genuine null pointer to get past the type checks. } + FxExpression *x = new FxConstant(cls, to, ScriptPosition); delete this; return x; } diff --git a/src/scripting/codegeneration/codegen.h b/src/scripting/codegeneration/codegen.h index 4f3b57c13..15ba2a933 100644 --- a/src/scripting/codegeneration/codegen.h +++ b/src/scripting/codegeneration/codegen.h @@ -364,12 +364,10 @@ public: isresolved = true; } - FxConstant(PClass *val, const FScriptPosition &pos) : FxExpression(pos) + FxConstant(PClass *val, PClassPointer *valtype, const FScriptPosition &pos) : FxExpression(pos) { value.pointer = (void*)val; - if (val != nullptr) ValueType = NewClassPointer(val); - else ValueType = NewClassPointer(RUNTIME_CLASS(DObject)); - value.Type = NewClassPointer(RUNTIME_CLASS(DObject)); + value.Type = ValueType = valtype; isresolved = true; }