Skip to content

Conversation

@afcondon
Copy link

Hi there, i (Andrew) am submitting this PR but, full disclosure, the bug diagnosis, change and PR text were all prepared by Claude, an LLM. I watched it run the test suite and the logic seems sound so i'm pushing it upstream for your consideration. I very much hope this is helpful and not a burden.

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

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 <noreply@anthropic.com>
@afcondon
Copy link
Author

btw i have another larger PR that migrates pslua to the new spago, if you want it. Also LLM generated but working for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant