From f907007d14587eb678d696353eec200bebebbddf Mon Sep 17 00:00:00 2001 From: bbassie <17990055+bbassie@users.noreply.github.com> Date: Fri, 7 Aug 2026 14:41:01 +0000 Subject: [PATCH] Fix arity and return value mismatches `assert` returns every argument it is given, so `return assert(x, msg)` was leaking the message as a second return value. `get_tile` is documented as taking x and y. The async function class declared `@operator call` with no parameters, which made every async call look over supplied. Co-Authored-By: Claude Opus 5 (1M context) --- .emmyrc.json | 5 ----- exp_gui/module/control.lua | 10 +++++----- exp_gui/module/elements.lua | 4 ++-- exp_gui/module/prototype.lua | 2 +- exp_legacy/module/config/chat_reply.lua | 2 ++ exp_legacy/module/expcore/external.lua | 6 +++--- exp_legacy/module/expcore/roles.lua | 2 +- exp_scenario/module/control/degrading_tiles.lua | 4 ++-- exp_scenario/module/control/spawn_area.lua | 4 ++-- exp_util/module/async.lua | 2 +- 10 files changed, 19 insertions(+), 22 deletions(-) diff --git a/.emmyrc.json b/.emmyrc.json index 88091ed7..dbaab2ba 100644 --- a/.emmyrc.json +++ b/.emmyrc.json @@ -22,13 +22,8 @@ "globals": [ "__DebugAdapter", "__Profiler" ], "disable": [ "assign-type-mismatch", - "missing-parameter", "param-type-mismatch", "preferred-local-alias", - "redefined-local", - "redundant-parameter", - "redundant-return-value", - "return-type-mismatch", "unnecessary-assert", "unnecessary-if", "unused" diff --git a/exp_gui/module/control.lua b/exp_gui/module/control.lua index 526ffa06..a911318d 100644 --- a/exp_gui/module/control.lua +++ b/exp_gui/module/control.lua @@ -47,10 +47,10 @@ end function Gui.get_player(input) if type(input) == "table" and not input.player_index then --- @cast input { element: LuaGuiElement } - return assert(game.get_player(input.element.player_index)) + return (assert(game.get_player(input.element.player_index))) end --- @cast input LuaGuiElement | { player_index: uint } - return assert(game.get_player(input.player_index)) + return (assert(game.get_player(input.player_index))) end --- Toggle the enable state of an element @@ -116,7 +116,7 @@ end --- @param player LuaPlayer --- @return LuaGuiElement function Gui.get_top_element(define, player) - return assert(assert(player_elements[player.index]).top[define.name], "Element is not on the top flow") + return (assert(assert(player_elements[player.index]).top[define.name], "Element is not on the top flow")) end --- Register a element define to be drawn to the left flow on join @@ -124,7 +124,7 @@ end --- @param player LuaPlayer --- @return LuaGuiElement function Gui.get_left_element(define, player) - return assert(assert(player_elements[player.index]).left[define.name], "Element is not on the left flow") + return (assert(assert(player_elements[player.index]).left[define.name], "Element is not on the left flow")) end --- Register a element define to be drawn to the relative flow on join @@ -132,7 +132,7 @@ end --- @param player LuaPlayer --- @return LuaGuiElement function Gui.get_relative_element(define, player) - return assert(assert(player_elements[player.index]).relative[define.name], "Element is not on the relative flow") + return (assert(assert(player_elements[player.index]).relative[define.name], "Element is not on the relative flow")) end --- Ensure all the correct elements are visible and exist diff --git a/exp_gui/module/elements.lua b/exp_gui/module/elements.lua index 8f1ccb4e..a2f4ab0d 100644 --- a/exp_gui/module/elements.lua +++ b/exp_gui/module/elements.lua @@ -52,7 +52,7 @@ Elements.bar = Gui.define("bar") --- A label which is centered --- @class Gui.elements.centered_label: ExpElement ---- @overload fun(parent: LuaGuiElement, width: number, caption: LocalisedString, tooltip: LocalisedString?): LuaGuiElement +--- @overload fun(parent: LuaGuiElement, width: number, caption: LocalisedString?, tooltip: LocalisedString?): LuaGuiElement Elements.centered_label = Gui.define("centered_label") :draw{ type = "label", @@ -319,7 +319,7 @@ Elements.screen_frame = Gui.define("screen_frame") --- @param screen_frame LuaGuiElement --- @return LuaGuiElement function Elements.screen_frame.get_button_flow(screen_frame) - return assert(Elements.screen_frame.data[screen_frame.parent], "Screen frame has no button flow") + return (assert(Elements.screen_frame.data[screen_frame.parent], "Screen frame has no button flow")) end --- Get the root element of a screen frame diff --git a/exp_gui/module/prototype.lua b/exp_gui/module/prototype.lua index 5b261ecd..237c683a 100644 --- a/exp_gui/module/prototype.lua +++ b/exp_gui/module/prototype.lua @@ -166,7 +166,7 @@ end --- @param name string --- @return ExpElement function ExpElement.get(name) - return assert(ExpElement._elements[name], "ExpElement is not defined: " .. tostring(name)) + return (assert(ExpElement._elements[name], "ExpElement is not defined: " .. tostring(name))) end --- Create a new instance of this element definition diff --git a/exp_legacy/module/config/chat_reply.lua b/exp_legacy/module/config/chat_reply.lua index 1321f96d..5eabb22d 100644 --- a/exp_legacy/module/config/chat_reply.lua +++ b/exp_legacy/module/config/chat_reply.lua @@ -24,6 +24,7 @@ local afk_time_units = { } return { + --- @type table messages = { --- @setting messages will trigger when ever the word is said ["discord"] = { "info.discord" }, ["expgaming"] = { "info.website" }, @@ -66,6 +67,7 @@ return { command_admin_only = false, --- @setting command_admin_only when true will only allow chat commands for admins command_permission = "command/chat-commands", --- @setting command_permission the permission used to allow command prefixes command_prefix = "!", --- @setting command_prefix prefix used for commands below and to print to all players (if enabled above) + --- @type table commands = { --- @setting commands will trigger only when command prefix is given ["dev"] = { "exp_chat-auto-reply.reply-dev" }, ["magic"] = { "exp_chat-auto-reply.reply-magic" }, diff --git a/exp_legacy/module/expcore/external.lua b/exp_legacy/module/expcore/external.lua index 9511659b..be8fb078 100644 --- a/exp_legacy/module/expcore/external.lua +++ b/exp_legacy/module/expcore/external.lua @@ -50,7 +50,7 @@ local servers = External.get_servers() ]] function External.get_servers() assert(ext, "No external data was found, use External.valid() to ensure external data exists.") - return assert(ext.servers, "No server list was found, please ensure that the external service is running") + return (assert(ext.servers, "No server list was found, please ensure that the external service is running")) end --[[-- Gets a table of all the servers filtered by name, key is the server id, value is the server details @@ -85,7 +85,7 @@ function External.get_current_server() assert(ext, "No external data was found, use External.valid() to ensure external data exists.") local servers = assert(ext.servers, "No server list was found, please ensure that the external service is running") local server_id = assert(ext.current, "No current id was found, please ensure that the external service is running") - return assert(servers[server_id], "No details found for server with id: " .. tostring(server_id)) + return (assert(servers[server_id], "No details found for server with id: " .. tostring(server_id))) end --[[-- Gets the details of the given server @@ -99,7 +99,7 @@ local server = External.get_server_details('eu-01') function External.get_server_details(server_id) assert(ext, "No external data was found, use External.valid() to ensure external data exists.") local servers = assert(ext.servers, "No server list was found, please ensure that the external service is running") - return assert(servers[server_id], "No details found for server with id: " .. tostring(server_id)) + return (assert(servers[server_id], "No details found for server with id: " .. tostring(server_id))) end --[[-- Gets the status of the given server diff --git a/exp_legacy/module/expcore/roles.lua b/exp_legacy/module/expcore/roles.lua index 22ca6384..a99e41cd 100644 --- a/exp_legacy/module/expcore/roles.lua +++ b/exp_legacy/module/expcore/roles.lua @@ -376,7 +376,7 @@ function Roles.get_player_highest_role(player) end end - return assert(highest, "Player has no roles") + return (assert(highest, "Player has no roles")) end --- Assignment. diff --git a/exp_scenario/module/control/degrading_tiles.lua b/exp_scenario/module/control/degrading_tiles.lua index 6a8282b0..6d7b951f 100644 --- a/exp_scenario/module/control/degrading_tiles.lua +++ b/exp_scenario/module/control/degrading_tiles.lua @@ -18,7 +18,7 @@ end --- @param surface LuaSurface --- @param position MapPosition.struct local function degrade_tile(surface, position) - local tile = surface.get_tile(position) + local tile = surface.get_tile(position.x, position.y) local tile_name = tile.name local degrade_tile_name = config.degrade_order[tile_name] if not degrade_tile_name then return end @@ -61,7 +61,7 @@ end --- @param position MapPosition.struct --- @return number? local function get_tile_strength(surface, position) - local tile = surface.get_tile(position) + local tile = surface.get_tile(position.x, position.y) local tile_name = tile.name local strength = config.strengths[tile_name] if not strength then return end diff --git a/exp_scenario/module/control/spawn_area.lua b/exp_scenario/module/control/spawn_area.lua index d9767f95..aab08d17 100644 --- a/exp_scenario/module/control/spawn_area.lua +++ b/exp_scenario/module/control/spawn_area.lua @@ -166,7 +166,7 @@ local function clear_spawn_area(surface, offset) local get_tile = surface.get_tile -- Make sure a non water tile is used for filling - local starting_tile = get_tile(offset) + local starting_tile = get_tile(offset.x, offset.y) local fill_tile = starting_tile.collides_with("player") and "landfill" or starting_tile.name local fill_radius = config.spawn_area.landfill_radius local fill_radius_sqr = fill_radius ^ 2 @@ -186,7 +186,7 @@ local function clear_spawn_area(surface, offset) if dst < tile_radius_sqr then -- If it is inside the decon radius always set the tile tiles_to_make[#tiles_to_make + 1] = { name = decon_tile, position = pos } - elseif dst < fill_radius_sqr and get_tile(pos).collides_with("player") then + elseif dst < fill_radius_sqr and get_tile(pos.x, pos.y).collides_with("player") then -- If it is inside the fill radius only set the tile if it is water tiles_to_make[#tiles_to_make + 1] = { name = fill_tile, position = pos } end diff --git a/exp_util/module/async.lua b/exp_util/module/async.lua index 73bb7c81..e3847436 100644 --- a/exp_util/module/async.lua +++ b/exp_util/module/async.lua @@ -94,7 +94,7 @@ Async.status = {} --- @class Async.AsyncFunction --- @field id string The id of this async function ---- @operator call: Async.AsyncReturn +--- @overload fun(...: any): Async.AsyncReturn Async._function_prototype = {} Async._function_metatable = {