fix: use bound argument n in Format.lua FFI instead of unbound number#2
Merged
Conversation
The native formatting functions in src/Data/Number/Format.lua passed an unbound variable `number` to string.format while the actual Number argument was bound as `n`. At runtime `number` resolved to a nil global, so toPrecisionNative/toFixedNative/toExponentialNative errored instead of formatting their input. Reference each function's real argument `n`. Closes #1
b0ce238 to
61f141b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1
The Lua FFI in
src/Data/Number/Format.luapassed an unbound variablenumbertostring.format, while the actualNumberargument is bound asn(the functions are curriedInt -> Number -> String, sodis the digit count andnis the number). At runtimenumberresolved to anilglobal, sotoPrecisionNative,toFixedNative, andtoExponentialNativeall errored instead of formatting their input.This replaces
numberwith the real argumentnin all three calls. Minimal change,srconly.Verified:
nix develop -c ./scripts/buildexits 0;luacheck --quiet --std min src/Data/Number/Format.luais clean (the 6accessing undefined variable number/unused argument nwarnings are gone). A direct Lua smoke test now formats numbers correctly (e.g.toPrecisionNative(6)(1234.56789)->1234.567890).Note:
toFixedNativestill uses the%d(integer) specifier rather than%f, which truncates floats and diverges from JStoFixed. That is a separate correctness defect tracked in the issue and intentionally left out of this minimal fix.