From 709b97900e2e131ddd8c9f15fe55f947e719af90 Mon Sep 17 00:00:00 2001 From: Andrew Condon Date: Sat, 10 Jan 2026 15:29:30 +0100 Subject: [PATCH] fix: wrap table literals in parentheses before indexing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In Lua, table constructor literals cannot be directly indexed without parentheses. The expression `{ ["key"] = val }["key"]` is a syntax error, while `({ ["key"] = val })["key"]` is valid. This fix adds the same `wrapPrec PrecAtom` wrapping to `VarIndex` that was already applied to `VarField`, ensuring table literals are properly parenthesized when used with bracket indexing. Fixes pattern matching on ADT constructors that would generate invalid Lua like: if "Mod∷Type.Ctor" == { ["$ctor"] = "Mod∷Type.Ctor" }["$ctor"] then Now correctly generates: if "Mod∷Type.Ctor" == ({ ["$ctor"] = "Mod∷Type.Ctor" })["$ctor"] then Co-Authored-By: Claude Opus 4.5 --- lib/Language/PureScript/Backend/Lua/Printer.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Language/PureScript/Backend/Lua/Printer.hs b/lib/Language/PureScript/Backend/Lua/Printer.hs index 5e8b419..5025a48 100644 --- a/lib/Language/PureScript/Backend/Lua/Printer.hs +++ b/lib/Language/PureScript/Backend/Lua/Printer.hs @@ -108,7 +108,7 @@ printRow = \case printVar ∷ Lua.Var → ADoc printVar = \case Lua.VarName name → printName name - Lua.VarIndex (Ann e) (Ann i) → printedExp e <> brackets (printedExp i) + Lua.VarIndex (Ann e) (Ann i) → wrapPrec PrecAtom (printExp e) <> brackets (printedExp i) Lua.VarField (Ann e) n → wrapPrec PrecAtom (printExp e) <> "." <> printName n printFunctionCall ∷ PADoc → [PADoc] → ADoc