fix(core): numeric string arithmetic coercion#432
Draft
Guikingone wants to merge 1 commit into
Draft
Conversation
Guikingone
force-pushed
the
fix/362-numeric-string-arithmetic
branch
from
July 2, 2026 16:15
494c6d7 to
b2f4166
Compare
Allow Str operands in arithmetic (+, -, *, /, %, **) by treating them as numeric at runtime, matching PHP semantics. Pure integer-form strings coerce to int; float-form strings (containing a dot or exponent) coerce to float. Leading-numeric strings emit a compile-time warning and use the numeric prefix. Type checker: accept Str in is_numeric_operand_type, produce Mixed result type when either operand is Str, and warn for constant non-numeric strings. Lowering: coerce Str to float for Div via StrToF, route Add/Sub/Mul through MixedNumericBinop with Str operands. Runtime: new __rt_str_is_float_form helper (ARM64 + x86_64) parses the string with strtoll + strtod and reports whether strtod consumed more bytes (float-form). MixedNumericBinop now checks string operands for float-form on both targets and routes to the float path when needed, fixing "1.5" + 3 producing int(4) instead of float(4.5). 9 regression tests added. Docs and arithmetic example updated.
Guikingone
force-pushed
the
fix/362-numeric-string-arithmetic
branch
from
July 2, 2026 17:05
b2f4166 to
a2a5489
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.
Allow Str operands in arithmetic (+, -, *, /, %, **) by treating them as numeric at runtime, matching PHP semantics. Pure integer-form strings coerce to int; float-form strings (containing a dot or exponent) coerce to float. Leading-numeric strings emit a compile-time warning and use the numeric prefix.
Type checker: accept Str in is_numeric_operand_type, produce Mixed result type when either operand is Str, and warn for constant non-numeric strings. Lowering: coerce Str to float for Div via StrToF, route Add/Sub/Mul through MixedNumericBinop with Str operands.
Runtime: new __rt_str_is_float_form helper (ARM64 + x86_64) parses the string with strtoll + strtod and reports whether strtod consumed more bytes (float-form). MixedNumericBinop now checks string operands for float-form on both targets and routes to the float path when needed, fixing "1.5" + 3 producing int(4) instead of float(4.5).
9 regression tests added. Docs and arithmetic example updated.
Fix #362