You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
/ binop throws DivisionByZeroError on PHP8 target (Dynamic division by zero) #166
I think this should be reported on Haxe github but since I guess that the answer will be to avoid using Dynamic I try to post it here because hscript is by default using Dynamic.
On the PHP target, Interp's default / binop (Interp.hx, initOps()):
binops.set("/", function(e1,e2) return me.expr(e1) / me.expr(e2));
relies on the native / operator on Dynamic operands. Since PHP 8.0, / throws DivisionByZeroError for any division by zero (including Float), whereas other targets (JS, etc.) return Infinity/NaN without throwing — per Haxe's own documented Float/IEEE754 semantics. Since Interp.expr() always operates in Dynamic, this cross-target guarantee silently breaks specifically on PHP8, even when both operands are genuinely Float at runtime.
Repro:
vari=newhscript.Interp();
i.variables.set("x", 1.0);
i.variables.set("y", 0.0);
i.execute(newhscript.Parser().parseString("x / y")); // throws on PHP8, returns Infinity on JS
Suggested fix guard the divisor explicitly instead of relying on the native operator, restoring cross-target consistency:
Activity