From f9ce3c4145aca7094a12ff06bc70329c9a53f0ee Mon Sep 17 00:00:00 2001 From: bbassie <17990055+bbassie@users.noreply.github.com> Date: Fri, 7 Aug 2026 11:11:16 +0000 Subject: [PATCH] Assert row lookups and narrow force and style reads Co-Authored-By: Claude Opus 5 (1M context) --- exp_legacy/module/modules/gui/warp-list.lua | 4 ++-- exp_scenario/module/commands/ratio.lua | 4 ++-- exp_scenario/module/control/death_markers.lua | 2 +- exp_scenario/module/control/spawn_area.lua | 2 +- exp_scenario/module/gui/research_milestones.lua | 2 +- exp_scenario/module/gui/science_production.lua | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/exp_legacy/module/modules/gui/warp-list.lua b/exp_legacy/module/modules/gui/warp-list.lua index bcb974ef..29c5a18a 100644 --- a/exp_legacy/module/modules/gui/warp-list.lua +++ b/exp_legacy/module/modules/gui/warp-list.lua @@ -799,7 +799,7 @@ Event.on_nth_tick(math.floor(60 / config.update_smoothing), function() end -- Check if the player is within range - local warp_pos = warp.position + local warp_pos = warp.position --[[@as MapPosition.struct]] if warp.surface == surface then local dx, dy = px - warp_pos.x, py - warp_pos.y local dist = (dx * dx) + (dy * dy) @@ -842,7 +842,7 @@ end) Event.add(defines.events.on_player_created, function(event) -- If the force has no spawn then make a spawn warp local player = game.players[event.player_index] - local force = player.force + local force = player.force --[[@as LuaForce]] local spawn_id = Warps.get_spawn_warp_id(force.name) if not spawn_id then local spawn_position = force.get_spawn_position(player.surface) diff --git a/exp_scenario/module/commands/ratio.lua b/exp_scenario/module/commands/ratio.lua index 2e12e444..201dd339 100644 --- a/exp_scenario/module/commands/ratio.lua +++ b/exp_scenario/module/commands/ratio.lua @@ -29,7 +29,7 @@ Commands.new("ratio", { "exp-commands_ratio.description" }) local amount_of_machines = 1 if items_per_second then - amount_of_machines = math.ceil(products[1].amount * crafts_per_second) + amount_of_machines = math.ceil(assert(assert(products[1]).amount) * crafts_per_second) end for _, ingredient in ipairs(ingredients) do @@ -43,7 +43,7 @@ Commands.new("ratio", { "exp-commands_ratio.description" }) for i, product in ipairs(products) do Commands.print{ product.type == "item" and "exp-commands_ratio.item-out" or "exp-commands_ratio.fluid-out", - math.round(product.amount * crafts_per_second, 3), + math.round(assert(product.amount) * crafts_per_second, 3), product.name } end diff --git a/exp_scenario/module/control/death_markers.lua b/exp_scenario/module/control/death_markers.lua index efb25694..24a74f30 100644 --- a/exp_scenario/module/control/death_markers.lua +++ b/exp_scenario/module/control/death_markers.lua @@ -31,7 +31,7 @@ local function create_map_tag(corpse_data) message = message .. " at " .. time end - corpse_data.tag = player.force.add_chart_tag(corpse_data.corpse.surface, { + corpse_data.tag = (player.force --[[@as LuaForce]]).add_chart_tag(corpse_data.corpse.surface, { position = corpse_data.corpse.position, icon = config.map_icon, text = message, diff --git a/exp_scenario/module/control/spawn_area.lua b/exp_scenario/module/control/spawn_area.lua index 365aba9d..6ac8bdf4 100644 --- a/exp_scenario/module/control/spawn_area.lua +++ b/exp_scenario/module/control/spawn_area.lua @@ -276,7 +276,7 @@ local function on_player_created(event) if config.resource_patches.enabled then create_resource_patches(surface, offset) end if config.turrets.enabled then update_turrets() end - player.force.set_spawn_position(offset, surface) + (player.force --[[@as LuaForce]]).set_spawn_position(offset, surface) player.teleport(offset, surface) end diff --git a/exp_scenario/module/gui/research_milestones.lua b/exp_scenario/module/gui/research_milestones.lua index 3863af68..e830ee0f 100644 --- a/exp_scenario/module/gui/research_milestones.lua +++ b/exp_scenario/module/gui/research_milestones.lua @@ -204,7 +204,7 @@ end --- @param row_index number --- @param row_data ExpGui_ResearchMilestones.elements.milestone_table.row_data function Elements.milestone_table.refresh_row(milestone_table, row_index, row_data) - local row = Elements.milestone_table.data[milestone_table][row_index] + local row = assert(Elements.milestone_table.data[milestone_table][row_index]) row.name.caption = row_data.name row.target.caption = row_data.target row.achieved.caption = row_data.achieved diff --git a/exp_scenario/module/gui/science_production.lua b/exp_scenario/module/gui/science_production.lua index d1647ff1..54c69fd3 100644 --- a/exp_scenario/module/gui/science_production.lua +++ b/exp_scenario/module/gui/science_production.lua @@ -193,7 +193,7 @@ Elements.science_table = Gui.define("science_production/science_table") local science_table = Gui.elements.scroll_table(parent, 190, 4) local no_production_label = Elements.no_production_label(science_table) Elements.no_production_label.refresh(no_production_label) - science_table.style.column_alignments[3] = "right" + (science_table.style --[[@as LuaStyle]]).column_alignments[3] = "right" return science_table end) :element_data{} --[[@as any]] @@ -280,7 +280,7 @@ function Elements.science_table.add_row(science_table, row_data) column_count = 2, } delta_table.style.padding = 0 - delta_table.style.column_alignments[1] = "right" + (delta_table.style --[[@as LuaStyle]]).column_alignments[1] = "right" -- Draw the net production label local net = Elements.production_label(science_table, row_data.net)