From 8aa1745e1db86e2535a97774d90c749a0012021e Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Wed, 10 Jun 2026 14:51:00 +0800 Subject: [PATCH] =?UTF-8?q?feat(parser):=20=E6=B7=BB=E5=8A=A0=E5=AF=B9Big*?= =?UTF-8?q?=E6=95=B0=E5=80=BC=E7=B1=BB=E5=9E=8B=E4=B8=8D=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=BF=90=E7=AE=97=E7=AC=A6=E7=9A=84=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在BinaryOpTrait中添加Big*类型运算符支持检查逻辑 - 检测到BigFloat、Decimal或BigInt类型使用不支持的运算符时抛出错误 - 添加测试用例验证模运算符%对BigFloat类型的不支持 - 添加测试用例验证按位与运算符&对Decimal类型的不支持 - 添加测试用例验证左移运算符<<对BigFloat类型的不支持 - 添加测试用例验证按位或运算符|对Decimal类型的不支持 --- phpunit/code/bigfloat-unsupported-mod.php | 9 ++++++++ phpunit/code/bigfloat-unsupported-shift.php | 9 ++++++++ phpunit/code/decimal-unsupported-bitand.php | 9 ++++++++ phpunit/code/decimal-unsupported-bitor.php | 9 ++++++++ phpunit/src/BigNumberUnsupportedOpTest.php | 24 +++++++++++++++++++++ src/Php/Parser/BinaryOpTrait.php | 6 ++++++ 6 files changed, 66 insertions(+) create mode 100644 phpunit/code/bigfloat-unsupported-mod.php create mode 100644 phpunit/code/bigfloat-unsupported-shift.php create mode 100644 phpunit/code/decimal-unsupported-bitand.php create mode 100644 phpunit/code/decimal-unsupported-bitor.php create mode 100644 phpunit/src/BigNumberUnsupportedOpTest.php diff --git a/phpunit/code/bigfloat-unsupported-mod.php b/phpunit/code/bigfloat-unsupported-mod.php new file mode 100644 index 00000000..fac352a5 --- /dev/null +++ b/phpunit/code/bigfloat-unsupported-mod.php @@ -0,0 +1,9 @@ +exec("Operator '%' is not supported for Big* numeric types", 'bigfloat-unsupported-mod.php'); + } + + public function testDecimalBitAnd() + { + $this->exec("Operator '&' is not supported for Big* numeric types", 'decimal-unsupported-bitand.php'); + } + + public function testBigFloatShiftLeft() + { + $this->exec("Operator '<<' is not supported for Big* numeric types", 'bigfloat-unsupported-shift.php'); + } + + public function testDecimalBitOr() + { + $this->exec("Operator '|' is not supported for Big* numeric types", 'decimal-unsupported-bitor.php'); + } +} diff --git a/src/Php/Parser/BinaryOpTrait.php b/src/Php/Parser/BinaryOpTrait.php index 0ff4147c..759051d9 100644 --- a/src/Php/Parser/BinaryOpTrait.php +++ b/src/Php/Parser/BinaryOpTrait.php @@ -106,6 +106,12 @@ trait BinaryOpTrait } } + // Any Big*-typed operand reaching here means no Big* block handled the operator + $bigTypes = [self::TYPE_BIGFLOAT, self::TYPE_DECIMAL, self::TYPE_BIGINT]; + if (in_array($leftType, $bigTypes, true) || in_array($rightType, $bigTypes, true)) { + $this->fatalError($left, "Operator '{$op}' is not supported for Big* numeric types"); + } + // Only promote between native types (Int ↔ Float). When one side is // php::Var, let the Variant operator handle type coercion so that // run-time PHP type-juggling rules are followed correctly.