diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index 919c6d9539..a8053badd0 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -10629,7 +10629,14 @@ FxExpression *FxReturnStatement::Resolve(FCompileContext &ctx) } PPrototype *retproto; - if (Args.Size() == 0) + + if (ctx.ReturnProto != nullptr && ctx.ReturnProto->ReturnTypes.Size() != Args.Size()) + { + ScriptPosition.Message(MSG_ERROR, "Incorrect number of return values. Got %u, but expected %u", Args.Size(), ctx.ReturnProto->ReturnTypes.Size()); + delete this; + return nullptr; + } + else if (Args.Size() == 0) { TArray none(0); retproto = NewPrototype(none, none); @@ -10645,7 +10652,7 @@ FxExpression *FxReturnStatement::Resolve(FCompileContext &ctx) } retproto = Args[0]->ReturnProto(); } - else if (ctx.ReturnProto != nullptr && ctx.ReturnProto->ReturnTypes.Size() == Args.Size()) + else { for (unsigned i = 0; i < Args.Size(); i++) { @@ -10660,12 +10667,6 @@ FxExpression *FxReturnStatement::Resolve(FCompileContext &ctx) } return this; // no point calling CheckReturn here. } - else - { - ScriptPosition.Message(MSG_ERROR, "Incorrect number of return values. Got %u, but expected %u", Args.Size(), ctx.ReturnProto->ReturnTypes.Size()); - delete this; - return nullptr; - } ctx.CheckReturn(retproto, ScriptPosition);