Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

/ binop throws DivisionByZeroError on PHP8 target (Dynamic division by zero)

オープン 初心者向け
#166 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
領域
compilers

調査の方向性

Interp.hx、具体的には initOps() とデフォルトの "/" binop から始め、続いて提供されている Parser と Interp の再現コードを PHP 8 と別の target で実行します。ゼロ除算の結果を、Haxe で文書化されている Float の動作と比較します。完了の条件は、PHP 8 でその式が例外をスローしなくなり、target 間で一貫した結果になることです。

索引モデルが issue の本文から書いたものです。

説明

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;
});
主要言語
Haxe
スター
307
フォーク
155
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

HaxeFoundation/hscript のほかの issue

HaxeFoundation/hscript の issue をすべて見る

似ている issue

Compilers の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。