Skip to content

fix: fromStringImpl is the 4-ary function its Fn4 declaration requires - #9

Merged
Unisay merged 1 commit into
masterfrom
issue-186/fromstring-fn4
Jul 13, 2026
Merged

fix: fromStringImpl is the 4-ary function its Fn4 declaration requires#9
Unisay merged 1 commit into
masterfrom
issue-186/fromstring-fn4

Conversation

@Unisay

Copy link
Copy Markdown
Collaborator

Problem

fromStringImpl is declared Fn4 String (Number -> Boolean) (forall a. a -> Maybe a) (forall a. Maybe a) (Maybe Number), but the Lua entry was a chain of nested single-argument closures, a shape it has carried since the fork's initial import. runFn4 (and the compiler's uncurried lift) call the implementation n-ary, fn(a, b, c, d), and Lua silently drops surplus arguments on a 1-ary function, so Data.Number.fromString returned the inner closure instead of a Maybe Number on every PureScript call path in the released v9.1.4.

Found by the FFI audit in purescript-lua/purescript-lua#186. It stayed invisible because the regression guard called the entry curried, fromStringImpl(s)(isFinite)(just)(nothing), which pinned the wrong convention, and no compiler golden exercises fromString.

Change

  • src/Data/Number.lua: flatten fromStringImpl to a single 4-ary function; the parse logic (parseFloat prefix tolerance, isFinite guard, Nothing on failure: the #93 semantics) is unchanged.
  • test/regression/number.lua: the guard calls the entry n-ary, the way runFn4 does. It was red against the old shape (all 7 fromString checks) and is green after.

Verification

scripts/test green (Format and Number suites). Reproduction against the released code through the real runFn4 fallback of the functions fork: runFn4(fromStringImpl)("1.5")(isFinite)(Just)(Nothing) had type function before and is Just 1.5 after; the direct post-lift call fromStringImpl("1.5", isFinite, Just, Nothing) behaves identically.

Suggested release: patch (v9.1.5) plus a package-set bump.

Refs purescript-lua/purescript-lua#186.

The entry was a chain of nested single-argument closures, but runFn4
calls the underlying implementation n-ary — fn(a, b, c, d) — and Lua
silently drops the surplus arguments on a 1-ary function, so
Data.Number.fromString returned the inner closure instead of a
Maybe Number on every PureScript call path (the runtime runFn4 fallback
and the compiler uncurried lift alike). Flatten the implementation to a
single 4-ary function and pin the n-ary convention in the regression
guard.
Refs purescript-lua/purescript-lua#186.
@Unisay
Unisayforce-pushed the issue-186/fromstring-fn4 branch from 6bc8978 to 39b77f6CompareJuly 13, 2026 13:58
@Unisay
Unisay merged commit b38c16d into masterJul 13, 2026
1 check passed
@Unisay
Unisay deleted the issue-186/fromstring-fn4 branch July 13, 2026 14:01
Sign up for freeto 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.

1 participant

@Unisay