Title: ordBooleanImpl aliases unsafeCoerceImpl: compare on Boolean crashes under Lua 5.1 · Issue #10 · purescript-lua/purescript-lua-prelude · GitHub
Open Graph Title: ordBooleanImpl aliases unsafeCoerceImpl: compare on Boolean crashes under Lua 5.1 · Issue #10 · purescript-lua/purescript-lua-prelude
X Title: ordBooleanImpl aliases unsafeCoerceImpl: compare on Boolean crashes under Lua 5.1 · Issue #10 · purescript-lua/purescript-lua-prelude
Description: src/Data/Ord.lua defines a single comparison helper and reuses it for every type: local unsafeCoerceImpl = function(lt) return function(eq) return function(gt) return function(x) return function(y) if x < y then return lt elseif x == y t...
Open Graph Description: src/Data/Ord.lua defines a single comparison helper and reuses it for every type: local unsafeCoerceImpl = function(lt) return function(eq) return function(gt) return function(x) return function(y)...
X Description: src/Data/Ord.lua defines a single comparison helper and reuses it for every type: local unsafeCoerceImpl = function(lt) return function(eq) return function(gt) return function(x) return function(y)...
Opengraph URL: https://github.com/purescript-lua/purescript-lua-prelude/issues/10
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ordBooleanImpl aliases unsafeCoerceImpl: compare on Boolean crashes under Lua 5.1","articleBody":"\n`src/Data/Ord.lua` defines a single comparison helper and reuses it for every type:\n\n```lua\nlocal unsafeCoerceImpl = function(lt)\n return function(eq)\n return function(gt)\n return function(x)\n return function(y)\n if x \u003c y then\n return lt\n elseif x == y then\n return eq\n else\n return gt\n end\n end\n end\n end\n end\nend\n\nreturn {\n ordBooleanImpl = (unsafeCoerceImpl),\n ...\n}\n```\n\nFor Int, Number, String and Char the `\u003c` operator is well defined in Lua, so reusing the helper is fine. For Boolean it is not. Lua 5.1 (the pslua target) raises a runtime error on relational operators between booleans:\n\n```\n$ lua -e 'print(pcall(function() return false \u003c true end))'\nfalse\t(command line):1: attempt to compare two boolean values\n```\n\nSo any use of `Ord Boolean` (`compare`, `\u003c`, `\u003c=`, `min`, `max`, `clamp`) crashes at runtime instead of returning an ordering. The bug stays silent until a program actually compares two booleans.\n\n## Fix\n\nGive `ordBooleanImpl` its own implementation that orders `false \u003c true` without relying on `\u003c`:\n\n```lua\nordBooleanImpl = (function(lt)\n return function(eq)\n return function(gt)\n return function(x)\n return function(y)\n if not x and y then\n return lt\n elseif x == y then\n return eq\n else\n return gt\n end\n end\n end\n end\n end\nend),\n```\n\nA working implementation already exists in @UnrelatedString's #3. It will be carried over from there with credit as part of the upstream-sync pass. The other `ord*Impl` aliases are correct and should stay on the shared helper.\n\n## Test coverage\n\nThe fix must ship with a regression test that fails on the current alias and passes after the fix: assert `compare false true == LT`, `compare true false == GT`, `compare true true == EQ`, and that `min`/`max` on Boolean do not error. This belongs in the prelude test suite being revived during upstream-sync. Without it the crash can regress unnoticed, since luacheck does not exercise the comparison.\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-06-14T11:11:13Z","url":"https://github.com/purescript-lua/purescript-lua-prelude/issues/10"}
| 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:90435bec-28d9-3e59-9308-b63027b55858 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C8EE:213839:F8F5F5:140E46F:6B01009F |
| html-safe-nonce | b4d438f4f3467dd360c6a3be34e89e18f1bc2322fe9b2f50b95d92ef3194e670 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOEVFOjIxMzgzOTpGOEY1RjU6MTQwRTQ2Rjo2QjAxMDA5RiIsInZpc2l0b3JfaWQiOiI1OTczODg4NzI2OTc0MTM2NDc5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | ae4450fd045f2efc9261fd842699b67dae576f6dc78d1b20a3d484e71db21844 |
| hovercard-subject-tag | issue:4658876503 |
| 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-prelude/10/issue_layout |
| twitter:image | https://opengraph.githubassets.com/afd18c95e77ba3ffcec550dd3b1495924c226df9862f77ca215f23cca40f906c/purescript-lua/purescript-lua-prelude/issues/10 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/afd18c95e77ba3ffcec550dd3b1495924c226df9862f77ca215f23cca40f906c/purescript-lua/purescript-lua-prelude/issues/10 |
| og:image:alt | src/Data/Ord.lua defines a single comparison helper and reuses it for every type: local unsafeCoerceImpl = function(lt) return function(eq) return function(gt) return function(x) return function(y)... |
| 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 | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| turbo-cache-control | no-preview |
| go-import | github.com/purescript-lua/purescript-lua-prelude git https://github.com/purescript-lua/purescript-lua-prelude.git |
| octolytics-dimension-user_id | 131581790 |
| octolytics-dimension-user_login | purescript-lua |
| octolytics-dimension-repository_id | 620956647 |
| octolytics-dimension-repository_nwo | purescript-lua/purescript-lua-prelude |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | true |
| octolytics-dimension-repository_parent_id | 33838632 |
| octolytics-dimension-repository_parent_nwo | purescript/purescript-prelude |
| octolytics-dimension-repository_network_root_id | 33838632 |
| octolytics-dimension-repository_network_root_nwo | purescript/purescript-prelude |
| 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 | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width