From f39da0c585253ebc4ad2161cdc47b46d05b2e600 Mon Sep 17 00:00:00 2001 From: bbassie <17990055+bbassie@users.noreply.github.com> Date: Thu, 6 Aug 2026 21:52:59 +0000 Subject: [PATCH] Type the last of the forward declarations Locals declared ahead of an assignment inside a callback were inferred as nil at every use site. The role event handlers are given a class so the table is not unified with the other module handler tables. Co-Authored-By: Claude Opus 5 (1M context) --- exp_commands/module/search.lua | 2 +- exp_legacy/module/config/warnings.lua | 1 + exp_legacy/module/expcore/roles.lua | 5 +++-- exp_legacy/module/modules/control/warnings.lua | 2 +- exp_roles/module/events.lua | 7 ++++++- exp_scenario/module/control/deconstruction_log.lua | 4 +++- exp_scenario/module/gui/player_list.lua | 2 +- 7 files changed, 16 insertions(+), 7 deletions(-) diff --git a/exp_commands/module/search.lua b/exp_commands/module/search.lua index 8e0176e9..a75de6a8 100644 --- a/exp_commands/module/search.lua +++ b/exp_commands/module/search.lua @@ -66,7 +66,7 @@ function Search.on_player_locale_changed(event) local ids = player.request_translations(required_translations) assert(ids, "Translation ids was nil") for i, command_name in ipairs(command_names) do - pending[ids[i]] = { locale, command_name } + pending[assert(ids[i])] = { locale, command_name } end end end diff --git a/exp_legacy/module/config/warnings.lua b/exp_legacy/module/config/warnings.lua index e098dc2f..b60e003b 100644 --- a/exp_legacy/module/config/warnings.lua +++ b/exp_legacy/module/config/warnings.lua @@ -2,6 +2,7 @@ -- @config Warnings return { + --- @type (LocalisedString[] | fun(player: LuaPlayer, by_player_name: string, number_of_warnings: number))[] actions = { --- @setting actions what actions are taking at number of warnings -- if a localized string is used then __1__ will by_player_name and __2__ will be the current warning count (auto inserted) { "warnings.received", "" }, diff --git a/exp_legacy/module/expcore/roles.lua b/exp_legacy/module/expcore/roles.lua index d3698f3e..529752d2 100644 --- a/exp_legacy/module/expcore/roles.lua +++ b/exp_legacy/module/expcore/roles.lua @@ -1115,8 +1115,9 @@ local function role_update(event) -- Updates the players permission group local highest = Roles.get_player_highest_role(player) if highest.permission_group then - if highest.permission_group[1] then - local group = game.permissions.get_group(highest.permission_group[2]) + local permission_group = highest.permission_group --[[@as [boolean, string] ]] + if permission_group[1] then + local group = game.permissions.get_group(permission_group[2]) if group then Groups.add_to_permission_group_async(group, player) end diff --git a/exp_legacy/module/modules/control/warnings.lua b/exp_legacy/module/modules/control/warnings.lua index 628fc8d0..6a0fa116 100644 --- a/exp_legacy/module/modules/control/warnings.lua +++ b/exp_legacy/module/modules/control/warnings.lua @@ -107,7 +107,7 @@ function Warnings.add_warning(player, by_player_name, reason) reason = reason or "None given." - local warning_count + local warning_count --- @type number PlayerWarnings:update(player.name, function(_, warnings) local warning = { by_player_name = by_player_name, diff --git a/exp_roles/module/events.lua b/exp_roles/module/events.lua index 6537b5c1..12d8456d 100644 --- a/exp_roles/module/events.lua +++ b/exp_roles/module/events.lua @@ -9,7 +9,10 @@ had, and event_handler expects `events` to be the handlers to register. local clusterio_api = require("modules/clusterio/api") local ExpRoles = require("modules/exp_roles/control") -return { +--- @class ExpRoles.EventHandlers +--- @field on_load fun() +--- @field events table +local handlers = { on_load = ExpRoles.on_load, events = { [clusterio_api.events.on_server_startup] = ExpRoles.on_server_startup, @@ -17,3 +20,5 @@ return { [defines.events.on_player_joined_game] = ExpRoles.on_player_joined_game, }, } + +return handlers diff --git a/exp_scenario/module/control/deconstruction_log.lua b/exp_scenario/module/control/deconstruction_log.lua index 087030ab..98ceb9ea 100644 --- a/exp_scenario/module/control/deconstruction_log.lua +++ b/exp_scenario/module/control/deconstruction_log.lua @@ -137,7 +137,9 @@ local function on_player_ammo_inventory_changed(event) if not player or not player.character then return end local character_ammo = assert(player.get_inventory(defines.inventory.character_ammo)) - local item = character_ammo[player.character.selected_gun_index] + local gun_index = player.character.selected_gun_index + --- @cast gun_index uint + local item = character_ammo[gun_index] if not item or not item.valid or not item.valid_for_read then return end diff --git a/exp_scenario/module/gui/player_list.lua b/exp_scenario/module/gui/player_list.lua index a5db97b1..bb3a70e3 100644 --- a/exp_scenario/module/gui/player_list.lua +++ b/exp_scenario/module/gui/player_list.lua @@ -102,7 +102,7 @@ Elements.reason_confirm = Gui.define("player_list/reason_confirm") local action_name = Elements.container.get_selected_action(player) local button_data = action_name and config.buttons[action_name] if button_data and button_data.reason_callback then - local reason = element.parent.entry.text + local reason = assert(assert(element.parent).entry).text --[[@as string?]] if reason == nil or not reason:find("%S") then reason = "no reason given" end button_data.reason_callback(player, reason) end