/ binop throws DivisionByZeroError on PHP8 target (Dynamic division by zero)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Domain
- compilers
Research direction
Start in Interp.hx, specifically initOps() and the default "/" binop, then run the provided Parser and Interp reproduction with PHP 8 and another target. Compare the division-by-zero result with Haxe's documented Float behavior; done means the expression no longer throws on PHP 8 and remains consistent across targets.
Written by the indexing model from the issue text.
Description
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:
var i = new hscript.Interp();
i.variables.set("x", 1.0);
i.variables.set("y", 0.0);
i.execute(new hscript.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:
binops.set("/", function(e1,e2){
var b = me.expr(e2);
return b == 0 ? Math.NaN : me.expr(e1) / b;
});
- Dominant language
- Haxe
- Stars
- 309
- Forks
- 154
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from HaxeFoundation/hscript
-
Difficulty 2/5 1-3 hours Newbie friendliness 50/100
HaxeFoundation/hscript#161 · 1 comment ·
-
Haxe4 try-catchOpen
Difficulty 4/5 3-5 days Newbie friendliness 35/100
HaxeFoundation/hscript#144 · 3 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
HaxeFoundation/hscript#109 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
HaxeFoundation/hscript#98 · 1 reaction ·
-
Difficulty 3/5 1-2 days Newbie friendliness 42/100
HaxeFoundation/hscript#96 · 3 comments ·
All issues in HaxeFoundation/hscript
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
checker: module referenced only inside a `sql db { ... }` block is reported as an unused importOpen
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day