Skip to content

reduceTableDefinitionAccessor ignores TableRowKV rows and duplicate fields (folds to Nil) #140

Description

@Unisay

The Lua optimizer rule reduceTableDefinitionAccessor (lib/Language/PureScript/Backend/Lua/Optimizer.hs) rewrites { foo = 1, bar = 2 }.foo to 1, but it searches only TableRowNV rows and takes the first match via listToMaybe, falling back to Nil.

Two latent hazards follow. If codegen ever emits a string key in KV form (["foo"] = 1) for a field that is later accessed with VarField, the rule folds the access to Nil instead of the value. And on duplicate field names Lua's table constructor keeps the last occurrence while the rule returns the first.

Neither shape is currently produced by the codegen, so this is hardening rather than a live miscompile: the rule should refuse to match when the constructor contains any TableRowKV row or duplicate field names.

Found during the 2026-07-02 backend audit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: codegenLua code generation / printingbugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions