From d699ba248e939c82e525e8c5785d26ff9ea093a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Lu=C3=ADs=20Vaz=20Silva?= Date: Sun, 15 Oct 2023 11:21:07 -0300 Subject: [PATCH] warn when fewer returns than expected are given for a function --- src/common/scripting/backend/codegen.cpp | 4 ++++ wadsrc/static/zscript/actors/inventory/stateprovider.zs | 4 ++-- wadsrc/static/zscript/doombase.zs | 6 ++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/common/scripting/backend/codegen.cpp b/src/common/scripting/backend/codegen.cpp index 2e4bb7e9e..d3d0a7186 100644 --- a/src/common/scripting/backend/codegen.cpp +++ b/src/common/scripting/backend/codegen.cpp @@ -11330,6 +11330,10 @@ FxExpression *FxReturnStatement::Resolve(FCompileContext &ctx) { mismatchSeverity = MSG_ERROR; } + else if (protoRetCount > retCount) + { // also warn when returning less values then the return count + mismatchSeverity = MSG_WARNING; + } } if (mismatchSeverity != -1) diff --git a/wadsrc/static/zscript/actors/inventory/stateprovider.zs b/wadsrc/static/zscript/actors/inventory/stateprovider.zs index 21295c315..e02287258 100644 --- a/wadsrc/static/zscript/actors/inventory/stateprovider.zs +++ b/wadsrc/static/zscript/actors/inventory/stateprovider.zs @@ -210,7 +210,7 @@ class StateProvider : Inventory action Actor, Actor A_FireProjectile(class missiletype, double angle = 0, bool useammo = true, double spawnofs_xy = 0, double spawnheight = 0, int flags = 0, double pitch = 0) { let player = self.player; - if (!player) return null; + if (!player) return null, null; let weapon = player.ReadyWeapon; @@ -220,7 +220,7 @@ class StateProvider : Inventory if (useammo && weapon && stateinfo != null && stateinfo.mStateType == STATE_Psprite) { if (!weapon.DepleteAmmo(weapon.bAltFire, true)) - return null; // out of ammo + return null, null; // out of ammo } if (missiletype) diff --git a/wadsrc/static/zscript/doombase.zs b/wadsrc/static/zscript/doombase.zs index 1ff7cead3..f6c8dcb00 100644 --- a/wadsrc/static/zscript/doombase.zs +++ b/wadsrc/static/zscript/doombase.zs @@ -122,11 +122,13 @@ extend class Object native static double G_SkillPropertyFloat(int p); deprecated("3.8", "Use Level.PickDeathMatchStart() instead") static vector3, int G_PickDeathmatchStart() { - return level.PickDeathmatchStart(); + let [a,b] = level.PickDeathmatchStart(); + return a, b; } deprecated("3.8", "Use Level.PickPlayerStart() instead") static vector3, int G_PickPlayerStart(int pnum, int flags = 0) { - return level.PickPlayerStart(pnum, flags); + let [a,b] = level.PickPlayerStart(pnum, flags); + return a, b; } deprecated("4.3", "Use S_StartSound() instead") native static void S_Sound (Sound sound_id, int channel, float volume = 1, float attenuation = ATTN_NORM, float pitch = 0.0, float startTime = 0.0); native static void S_StartSound (Sound sound_id, int channel, int flags = 0, float volume = 1, float attenuation = ATTN_NORM, float pitch = 0.0, float startTime = 0.0);