From 746e29c353679e28e18650816745bffca7303e97 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 10 Aug 2026 03:08:51 +0900 Subject: fix(php-src): assert php_gcvt's unported arguments up front php_gcvt only ports the ndigit < 0 (dtoa mode 0) path and hardcodes the '.'/'E' separators of its sole caller into the placement logic, but it accepted any argument and silently produced a wrong string for the rest. Assert the supported combination instead, and turn the mode 2 bail-out into unreachable! now that the assert rules it out. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe-php-src/src/main/snprintf.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/shirabe-php-src/src/main/snprintf.rs b/crates/shirabe-php-src/src/main/snprintf.rs index f1411d6e..c0a3f23a 100644 --- a/crates/shirabe-php-src/src/main/snprintf.rs +++ b/crates/shirabe-php-src/src/main/snprintf.rs @@ -6,9 +6,13 @@ /// produces the same digit string as `zend_dtoa` in mode 0 (both compute the unique shortest /// decimal that round-trips), so only the digit placement logic is ported here. pub fn php_gcvt(value: f64, ndigit: i32, dec_point: char, exponent: char) -> String { + assert!(ndigit == -1); + assert!(dec_point == '.'); + assert!(exponent == 'E'); + let mode = if ndigit >= 0 { 2 } else { 0 }; if mode != 0 { - todo!("php_gcvt is only ported for ndigit < 0 (serialize_precision=-1)"); + unreachable!("php_gcvt is only ported for ndigit < 0 (serialize_precision=-1)"); } let ndigit = 17i32; -- cgit v1.3.1-4-g156e