Skip to content

Scope Data.Int.toStringAs floor assignment to local during foreign import parsing#53

Closed
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-global-n-leak
Closed

Scope Data.Int.toStringAs floor assignment to local during foreign import parsing#53
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-global-n-leak

Conversation

Copilot AI commented Jun 14, 2026

Copy link
Copy Markdown

Data.Int.toStringAs in the upstream Lua FFI can emit n = floor(i), which writes a global and leaks mutable shared state. This change ensures the imported foreign source is normalized to local scope for that assignment in the known toStringAs shape.

  • Foreign import patching (targeted)

    • Updated Language.PureScript.Backend.Lua.Linker.Foreign.parseForeignSource to post-process parsed exports.
    • For export key toStringAs, when the value matches the expected Data.Int context (math.floor, table.insert, return function(i)), rewrite the specific assignment n = floor(i) to local n = floor(i).
    • Rewrite preserves original indentation.
  • Regression coverage

    • Extended Language.PureScript.Backend.Lua.Linker.Foreign.Spec fixture with a toStringAs export containing the leaking assignment.
    • Updated expected parsed output to assert the localized assignment appears in the emitted expression text.
-- before
n = floor(i)

-- after
local n = floor(i)

Copilot AI changed the title [WIP] Fix global n leak in Int.toStringAs function Scope Data.Int.toStringAs floor assignment to local during foreign import parsing Jun 14, 2026
Copilot AI requested a review from Unisay June 14, 2026 07:48
@Unisay

Unisay commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

The issue was a one-line fix, but it should have been done it the other repository.

@Unisay Unisay closed this Jun 14, 2026
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