Title: [fork-ffi] arrays: traverse1Impl — Faulty JS->Lua translation of the `new ConsCell(...)` / `new… · Issue #73 · purescript-lua/purescript-lua · GitHub
Open Graph Title: [fork-ffi] arrays: traverse1Impl — Faulty JS->Lua translation of the `new ConsCell(...)` / `new… · Issue #73 · purescript-lua/purescript-lua
X Title: [fork-ffi] arrays: traverse1Impl — Faulty JS->Lua translation of the `new ConsCell(...)` / `new… · Issue #73 · purescript-lua/purescript-lua
Description: Package: purescript-lua-arrays File: src/Data/Array/NonEmpty/Internal.lua Function: traverse1Impl Class: semantics Severity: high Faulty JS->Lua translation of the new ConsCell(...) / new Cont(...) constructor pattern. In JS these are in...
Open Graph Description: Package: purescript-lua-arrays File: src/Data/Array/NonEmpty/Internal.lua Function: traverse1Impl Class: semantics Severity: high Faulty JS->Lua translation of the new ConsCell(...) / new Cont(...)...
X Description: Package: purescript-lua-arrays File: src/Data/Array/NonEmpty/Internal.lua Function: traverse1Impl Class: semantics Severity: high Faulty JS->Lua translation of the new ConsCell(...) / new Cont(....
Opengraph URL: https://github.com/purescript-lua/purescript-lua/issues/73
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[fork-ffi] arrays: traverse1Impl — Faulty JS->Lua translation of the `new ConsCell(...)` / `new…","articleBody":"**Package:** purescript-lua-arrays \n**File:** `src/Data/Array/NonEmpty/Internal.lua` \n**Function:** `traverse1Impl` \n**Class:** semantics **Severity:** high\n\nFaulty JS->Lua translation of the `new ConsCell(...)` / `new Cont(...)` constructor pattern. In JS these are invoked with `new`, so each returns a freshly-allocated object. The Lua port rewrote them as functions taking an explicit `this` first parameter (`Cont(this, fn)`, `ConsCell(this, head, tail)`) that mutate `this` and return nil, but the call sites still call them with the *data* arguments only -- e.g. `finalCell(head)` calls `ConsCell(head, emptyList)`, so `this` = the head element and `this.head = ...` errors. `consList(x)(xs)` calls `ConsCell(x, xs)` and `go` returns `Cont(function() ... end)`, all likewise broken. The function errors on its very first real invocation. Confirmed under Lua 5.1: `attempt to index local 'this' (a number value)` at the `this.head = head` line. This breaks `traverse1`/`sequence1` for NonEmptyArray entirely.\n\n**Current (Lua):**\n```lua\nlocal function Cont(this, fn) this.fn = fn end\nlocal function ConsCell(this, head, tail)\n this.head = head\n this.tail = tail\nend\nlocal function finalCell(head) return ConsCell(head, emptyList) end\nlocal function consList(x) return function(xs) return ConsCell(x, xs) end end\n...\nreturn Cont(function() return go(buildFrom(last, acc), currentLen - 1, xs) end)\n```\n\n**Expected:** JS uses `new`, so the constructors allocate and return objects: `finalCell(h)` => {head=h, tail=emptyList}; `consList(x)(xs)` => {head=x, tail=xs}; `go` returns a Cont wrapper {fn=...}. `traverse1Impl(apply,map,f)(array)` must thread these cells through and produce the reversed-then-listToArray result. With Identity-style apply/map and f=(*10), `traverse1Impl(...)({1,2,3})` must yield {10,20,30}.\n\n**Proposed fix:**\n```lua\nMake the constructors return tables instead of mutating a phantom `this`:\n local function Cont(fn) return {fn = fn} end\n local function ConsCell(head, tail) return {head = head, tail = tail} end\nThe existing call sites (finalCell, consList, the `Cont(function() ... end)` in `go`) then work unchanged. Verified under Lua 5.1: yields {10,20,30}.\n```\n\n_Found by the FFI audit; reproduced under Lua 5.1._","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-06-15T11:23:51Z","url":"https://github.com/purescript-lua/purescript-lua/issues/73"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ee6c5e47-cc57-75bd-3601-a089cf97fb3f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 841C:4E3C:6A8D40:8F3CDC:6B00D600 |
| html-safe-nonce | 2cb09e4f88af79ba827201d9beac63b202364b661eefa1c00bf6585292b3bd41 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NDFDOjRFM0M6NkE4RDQwOjhGM0NEQzo2QjAwRDYwMCIsInZpc2l0b3JfaWQiOiI3NjU2NTAwNDk1MTMyOTcyNTQ0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | ad1138432c8803e0564c43dbb2519ab8812b9135a25e63b064cd3783c917d39a |
| hovercard-subject-tag | issue:4664606158 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/purescript-lua/purescript-lua/73/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2596a207c0dfa5b4e2c871608f9be82b74a5021c251ced0feff58807c1130717/purescript-lua/purescript-lua/issues/73 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2596a207c0dfa5b4e2c871608f9be82b74a5021c251ced0feff58807c1130717/purescript-lua/purescript-lua/issues/73 |
| og:image:alt | Package: purescript-lua-arrays File: src/Data/Array/NonEmpty/Internal.lua Function: traverse1Impl Class: semantics Severity: high Faulty JS->Lua translation of the new ConsCell(...) / new Cont(...)... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Unisay |
| hostname | github.com |
| expected-hostname | github.com |
| None | a481f62a1e04c9b9bdcb5628230682c66d59006f5b13b080f79cba84a176905b |
| turbo-cache-control | no-preview |
| go-import | github.com/purescript-lua/purescript-lua git https://github.com/purescript-lua/purescript-lua.git |
| octolytics-dimension-user_id | 131581790 |
| octolytics-dimension-user_login | purescript-lua |
| octolytics-dimension-repository_id | 587200487 |
| octolytics-dimension-repository_nwo | purescript-lua/purescript-lua |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 587200487 |
| octolytics-dimension-repository_network_root_nwo | purescript-lua/purescript-lua |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 84c8c5cc25e2fb7f2308428458538436baecc6d2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width