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.

@afcondon
Copy link
Author

I see this failed CI but it was not a test that failed, the build ran out of space "copyFile: resource exhausted (No space left on device)"

@Unisay
Copy link
Owner

Unisay commented Jan 19, 2026

Hi Andrew,

I am glad you're interested in using and contributing to this project!

I see this PR delivers a fix without unit-test coverage. Please add a unit test (golden test) to demonstrate the problem being fixed (the idea is that without this fix the test should fail and in a way that is understandable)

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a Lua syntax error when table constructor literals are directly indexed with bracket notation. In Lua, expressions like {key = val}[key] are invalid syntax, requiring parentheses: ({key = val})[key].

Changes:

  • Modified printVar function in the Lua printer to wrap table constructors in parentheses before bracket indexing, making VarIndex consistent with the existing VarField behavior

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants