Title: [fork-ffi] integers: fromNumberImpl — fromNumber must return Nothing when the Number is not an integer or… · Issue #85 · purescript-lua/purescript-lua · GitHub
Open Graph Title: [fork-ffi] integers: fromNumberImpl — fromNumber must return Nothing when the Number is not an integer or… · Issue #85 · purescript-lua/purescript-lua
X Title: [fork-ffi] integers: fromNumberImpl — fromNumber must return Nothing when the Number is not an integer or… · Issue #85 · purescript-lua/purescript-lua
Description: Package: purescript-lua-integers File: src/Data/Int.lua Function: fromNumberImpl Class: semantics Severity: high fromNumber must return Nothing when the Number is not an integer or falls outside the Int32 range. The upstream JS is return...
Open Graph Description: Package: purescript-lua-integers File: src/Data/Int.lua Function: fromNumberImpl Class: semantics Severity: high fromNumber must return Nothing when the Number is not an integer or falls outside th...
X Description: Package: purescript-lua-integers File: src/Data/Int.lua Function: fromNumberImpl Class: semantics Severity: high fromNumber must return Nothing when the Number is not an integer or falls outside th...
Opengraph URL: https://github.com/purescript-lua/purescript-lua/issues/85
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[fork-ffi] integers: fromNumberImpl — fromNumber must return Nothing when the Number is not an integer or…","articleBody":"**Package:** purescript-lua-integers \n**File:** `src/Data/Int.lua` \n**Function:** `fromNumberImpl` \n**Class:** semantics **Severity:** high\n\nfromNumber must return Nothing when the Number is not an integer or falls outside the Int32 range. The upstream JS is `return (n | 0) === n ? just(n) : nothing;` — it truncates to Int32 and only returns Just when the value is unchanged. The Lua version computes `math.modf(n)` (which discards the fractional part) and ALWAYS returns `just(i)`, so it never returns Nothing. This breaks the package's own tests: `fromNumber 0.9 == Nothing` and `fromNumber (-0.9) == Nothing` (Test/Data/Int.purs lines 22-23) — the Lua returns Just 0. Out-of-range inputs (e.g. 2147483648.0) also wrongly yield Just instead of Nothing.\n\n**Current (Lua):**\n```lua\nfromNumberImpl = (function(just)\n return function(nothing)\n return function(n)\n local i = math.modf(n)\n return just(i)\n end\n end\nend),\n```\n\n**Expected:** Nothing for any non-integral Number (fromNumber 0.9 == Nothing) and for any value outside [-2147483648, 2147483647]; Just n only when n is an integer within Int32 range.\n\n**Proposed fix:**\n```lua\nreturn function(n)\n local i = math.modf(n)\n if i == n and n >= -2147483648 and n \u003c= 2147483647 then\n return just(n)\n end\n return nothing\nend\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:24:05Z","url":"https://github.com/purescript-lua/purescript-lua/issues/85"}
| 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:5adf1251-dfcb-a4e4-2287-3a539c888e5e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 95C8:29FFA9:66E616:8425D9:6B00DFA6 |
| html-safe-nonce | 326b0399c267bf064b3d56847b9e77ba844e0592432d3425dd9e034cfec6b442 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NUM4OjI5RkZBOTo2NkU2MTY6ODQyNUQ5OjZCMDBERkE2IiwidmlzaXRvcl9pZCI6Ijc2ODY0ODQ5MDMwNzE4OTk1NTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e37b8e4c015e8ff782943008f93573814048f2b3d0ac84fcce72a34a0691ff8f |
| hovercard-subject-tag | issue:4664607788 |
| 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/85/issue_layout |
| twitter:image | https://opengraph.githubassets.com/aae17ce04eb2dd432edba4efb5806d1b7ad2881dc993e13f14673fe4d6decb33/purescript-lua/purescript-lua/issues/85 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/aae17ce04eb2dd432edba4efb5806d1b7ad2881dc993e13f14673fe4d6decb33/purescript-lua/purescript-lua/issues/85 |
| og:image:alt | Package: purescript-lua-integers File: src/Data/Int.lua Function: fromNumberImpl Class: semantics Severity: high fromNumber must return Nothing when the Number is not an integer or falls outside th... |
| 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 | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| 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 | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width