From 8e5b9e8076931426c2e0c3b8254f20fef0527ae6 Mon Sep 17 00:00:00 2001 From: Yurun Date: Wed, 17 Jun 2026 20:12:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(compiler)):=20=E4=BF=AE=E5=A4=8D=E9=99=A4?= =?UTF-8?q?=E4=BB=A5=E9=9B=B6MSVC=E7=BC=96=E8=AF=91=E4=B8=8D=E9=80=9A?= =?UTF-8?q?=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Php/Parser/BinaryOpTrait.php | 18 ++++++++++++++++++ tests/aot/float_edge/edge-cases.phpt | 2 ++ 2 files changed, 20 insertions(+) diff --git a/src/Php/Parser/BinaryOpTrait.php b/src/Php/Parser/BinaryOpTrait.php index c69f639a..efd214ec 100644 --- a/src/Php/Parser/BinaryOpTrait.php +++ b/src/Php/Parser/BinaryOpTrait.php @@ -125,6 +125,10 @@ trait BinaryOpTrait return 'php::fn::mod(' . $leftExpr . ', ' . $rightExpr . ')'; } + if ($op === '/' and $this->isZeroLiteral($right)) { + return self::VALUE_NAN; + } + return '((' . $leftExpr . ') ' . $op . ' (' . $rightExpr . '))'; } @@ -353,6 +357,20 @@ trait BinaryOpTrait return $this->parseBinaryOp($expr->left, $expr->right, '/'); } + private function isZeroLiteral(NodeAbstract $expr): bool + { + if ($expr instanceof Node\Scalar\Int_) { + return $expr->value == 0; + } + if ($expr instanceof Node\Scalar\Float_) { + return $expr->value == 0.0; + } + if ($expr instanceof Node\Scalar\String_) { + return $expr->value === '0' || $expr->value === '0.0'; + } + return false; + } + protected function parseBinaryOpMinus(Expr\BinaryOp\Minus $expr): string { return $this->parseBinaryOp($expr->left, $expr->right, '-'); diff --git a/tests/aot/float_edge/edge-cases.phpt b/tests/aot/float_edge/edge-cases.phpt index 1afab394..662325c1 100644 --- a/tests/aot/float_edge/edge-cases.phpt +++ b/tests/aot/float_edge/edge-cases.phpt @@ -19,6 +19,7 @@ function main(): void { var_dump(INF + INF); var_dump(INF / INF); var_dump(0.0 / 0.0); + var_dump(1.0 / 0.0); } ?> --EXPECT-- @@ -38,3 +39,4 @@ INF float(INF) float(NAN) float(NAN) +float(NAN)