- Add detectTypeOfExpr support for unary and binary logical operators - Implement proper bool conversion for big integer, float and decimal types - Update convertBoolExpr to skip conversion when type is already BOOL - Add convertConditionExpr method to handle big number truth values - Modify empty() implementation to use numeric truth values for big numbers - Enhance ternary operator type detection with conditional logic - Update loop control parsing to use condition expression conversion - Add proper type assertions for XOR logical operations - Remove redundant isValidDefineName tests from TraitsTest - Simplify ConstantExpressionValidationVisitor initialization - Initialize cValue variable in gen_stub.php for constant assertions - Add comprehensive tests for big number logical and unary operators - Add operator error boundary tests with PHP-compatible exception types - Add reverse and compound operator tests for big numeric typespull/44/head
parent
f38b6cf0c2
commit
21d0224769
12 changed files with 238 additions and 38 deletions
@ -0,0 +1,70 @@ |
|||||||
|
--TEST-- |
||||||
|
Big numeric unary plus and boolean contexts use numeric truth values |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
declare(strict_types=1); |
||||||
|
use native_types; |
||||||
|
|
||||||
|
function main(): void { |
||||||
|
$bi0 = std::bigInt(0); |
||||||
|
$bi1 = std::bigInt(1); |
||||||
|
echo (+$bi1)->toString(), "\n"; |
||||||
|
var_dump(!$bi0, !$bi1); |
||||||
|
var_dump($bi0 && $bi1, $bi0 || $bi1, ($bi1 xor $bi1), ($bi0 xor $bi1)); |
||||||
|
|
||||||
|
$dec0 = std::decimal("0.0"); |
||||||
|
$dec1 = std::decimal("1.0"); |
||||||
|
echo (+$dec1)->toString(), "\n"; |
||||||
|
var_dump(!$dec0, !$dec1); |
||||||
|
var_dump($dec0 && $dec1, $dec0 || $dec1, ($dec1 xor $dec1), ($dec0 xor $dec1)); |
||||||
|
|
||||||
|
$bf0 = std::bigFloat("0"); |
||||||
|
$bf1 = std::bigFloat("1"); |
||||||
|
echo (+$bf1)->toString(), "\n"; |
||||||
|
var_dump(!$bf0, !$bf1); |
||||||
|
var_dump($bf0 && $bf1, $bf0 || $bf1, ($bf1 xor $bf1), ($bf0 xor $bf1)); |
||||||
|
|
||||||
|
echo $bi0 ? "bad-if\n" : "if-ok\n"; |
||||||
|
echo $dec0 ? "bad-ternary\n" : "ternary-ok\n"; |
||||||
|
echo ($bf0 ?: std::bigFloat("9"))->toString(), "\n"; |
||||||
|
var_dump(empty($bi0), empty($bi1)); |
||||||
|
|
||||||
|
while ($bi0) { |
||||||
|
echo "bad-while\n"; |
||||||
|
} |
||||||
|
for (; $dec0;) { |
||||||
|
echo "bad-for\n"; |
||||||
|
} |
||||||
|
do { |
||||||
|
echo "do-once\n"; |
||||||
|
} while ($bf0); |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
1 |
||||||
|
bool(true) |
||||||
|
bool(false) |
||||||
|
bool(false) |
||||||
|
bool(true) |
||||||
|
bool(false) |
||||||
|
bool(true) |
||||||
|
1.0 |
||||||
|
bool(true) |
||||||
|
bool(false) |
||||||
|
bool(false) |
||||||
|
bool(true) |
||||||
|
bool(false) |
||||||
|
bool(true) |
||||||
|
1 |
||||||
|
bool(true) |
||||||
|
bool(false) |
||||||
|
bool(false) |
||||||
|
bool(true) |
||||||
|
bool(false) |
||||||
|
bool(true) |
||||||
|
if-ok |
||||||
|
ternary-ok |
||||||
|
9 |
||||||
|
bool(true) |
||||||
|
bool(false) |
||||||
|
do-once |
||||||
@ -0,0 +1,52 @@ |
|||||||
|
--TEST-- |
||||||
|
Big numeric operator error boundaries use PHP-compatible exception types |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
declare(strict_types=1); |
||||||
|
use native_types; |
||||||
|
|
||||||
|
function main(): void { |
||||||
|
try { |
||||||
|
$unused = std::bigInt(1) / 0; |
||||||
|
} catch (DivisionByZeroError $e) { |
||||||
|
echo "bigint division by zero\n"; |
||||||
|
} |
||||||
|
|
||||||
|
try { |
||||||
|
$unused = std::bigInt(1) % 0; |
||||||
|
} catch (DivisionByZeroError $e) { |
||||||
|
echo "bigint modulo by zero\n"; |
||||||
|
} |
||||||
|
|
||||||
|
try { |
||||||
|
$unused = std::bigInt(2) ** -1; |
||||||
|
} catch (TypeError $e) { |
||||||
|
echo "bigint negative exponent\n"; |
||||||
|
} |
||||||
|
|
||||||
|
try { |
||||||
|
$unused = std::decimal("1") % 0; |
||||||
|
} catch (DivisionByZeroError $e) { |
||||||
|
echo "decimal modulo by zero\n"; |
||||||
|
} |
||||||
|
|
||||||
|
try { |
||||||
|
$unused = std::decimal("NaN") <=> std::decimal("1"); |
||||||
|
} catch (ArithmeticError $e) { |
||||||
|
echo "decimal NaN comparison\n"; |
||||||
|
} |
||||||
|
|
||||||
|
try { |
||||||
|
$unused = std::bigFloat("NAN") <=> std::bigFloat("1"); |
||||||
|
} catch (ArithmeticError $e) { |
||||||
|
echo "bigfloat NaN comparison\n"; |
||||||
|
} |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
bigint division by zero |
||||||
|
bigint modulo by zero |
||||||
|
bigint negative exponent |
||||||
|
decimal modulo by zero |
||||||
|
decimal NaN comparison |
||||||
|
bigfloat NaN comparison |
||||||
@ -0,0 +1,42 @@ |
|||||||
|
--TEST-- |
||||||
|
Big numeric reverse non-commutative and BigFloat compound operators |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
declare(strict_types=1); |
||||||
|
use native_types; |
||||||
|
|
||||||
|
function main(): void { |
||||||
|
$bi = std::bigInt(4); |
||||||
|
echo (10 - $bi)->toString(), "\n"; |
||||||
|
echo (10 / $bi)->toString(), "\n"; |
||||||
|
echo (10 % $bi)->toString(), "\n"; |
||||||
|
echo (std::bigInt(-7) / 3)->toString(), "\n"; |
||||||
|
echo (std::bigInt(-7) % 3)->toString(), "\n"; |
||||||
|
|
||||||
|
$dec = std::decimal("4.0"); |
||||||
|
echo (10 - $dec)->toString(), "\n"; |
||||||
|
echo (10 / $dec)->toString(), "\n"; |
||||||
|
echo (10 % $dec)->toString(), "\n"; |
||||||
|
|
||||||
|
$bf = std::bigFloat("4.0"); |
||||||
|
echo (10 - $bf)->toString(), "\n"; |
||||||
|
echo (10 / $bf)->toString(), "\n"; |
||||||
|
$bf += 2; |
||||||
|
$bf -= 1; |
||||||
|
$bf *= 3; |
||||||
|
$bf /= 5; |
||||||
|
echo $bf->toString(), "\n"; |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
6 |
||||||
|
2 |
||||||
|
2 |
||||||
|
-2 |
||||||
|
-1 |
||||||
|
6.0 |
||||||
|
2.5 |
||||||
|
2.0 |
||||||
|
6 |
||||||
|
2.5 |
||||||
|
3 |
||||||
Loading…
Reference in new issue