Improve "unsupported operands" error

By mentioning the operand types. We can do that now, as the
original operand types now remain available.

Closes GH-5330.
This commit is contained in:
Nikita Popov 2020-04-01 10:05:26 +02:00
parent 9c0afc859c
commit cdaf35033d
16 changed files with 50 additions and 43 deletions

View file

@ -20,9 +20,9 @@ var_dump($c);
echo "Done\n"; echo "Done\n";
?> ?>
--EXPECTF-- --EXPECTF--
Exception: Unsupported operand types Exception: Unsupported operand types: array + object
Fatal error: Uncaught Error: Unsupported operand types in %s:%d Fatal error: Uncaught TypeError: Unsupported operand types: array + object in %s:%d
Stack trace: Stack trace:
#0 {main} #0 {main}
thrown in %s on line %d thrown in %s on line %d

View file

@ -22,11 +22,11 @@ echo "Done\n";
--EXPECTF-- --EXPECTF--
Notice: Object of class stdClass could not be converted to number in %sadd_003.php on line %d Notice: Object of class stdClass could not be converted to number in %sadd_003.php on line %d
Exception: Unsupported operand types Exception: Unsupported operand types: object + array
Notice: Object of class stdClass could not be converted to number in %s on line %d Notice: Object of class stdClass could not be converted to number in %s on line %d
Fatal error: Uncaught Error: Unsupported operand types in %s:%d Fatal error: Uncaught TypeError: Unsupported operand types: object + array in %s:%d
Stack trace: Stack trace:
#0 {main} #0 {main}
thrown in %s on line %d thrown in %s on line %d

View file

@ -17,9 +17,9 @@ var_dump($c);
echo "Done\n"; echo "Done\n";
?> ?>
--EXPECTF-- --EXPECTF--
Exception: Unsupported operand types Exception: Unsupported operand types: array + int
Fatal error: Uncaught Error: Unsupported operand types in %s:%d Fatal error: Uncaught TypeError: Unsupported operand types: array + int in %s:%d
Stack trace: Stack trace:
#0 {main} #0 {main}
thrown in %s on line %d thrown in %s on line %d

View file

@ -19,9 +19,9 @@ var_dump($c);
echo "Done\n"; echo "Done\n";
?> ?>
--EXPECTF-- --EXPECTF--
Exception: Unsupported operand types Exception: Unsupported operand types: array + string
Fatal error: Uncaught Error: Unsupported operand types in %s:%d Fatal error: Uncaught TypeError: Unsupported operand types: array + string in %s:%d
Stack trace: Stack trace:
#0 {main} #0 {main}
thrown in %s on line %d thrown in %s on line %d

View file

@ -31,7 +31,7 @@ try {
} }
?> ?>
--EXPECT-- --EXPECT--
Unsupported operand types Unsupported operand types: array - array
Unsupported operand types Unsupported operand types: array * array
Unsupported operand types Unsupported operand types: array / array
Unsupported operand types Unsupported operand types: array ** array

View file

@ -3,5 +3,8 @@ Constant Expressions with unsupported operands 001
--FILE-- --FILE--
<?php <?php
const T = array(1,2) - array(0); const T = array(1,2) - array(0);
--EXPECTF-- --EXPECT--
Fatal error: Unsupported operand types in %sconstant_expressions_exceptions_001.php on line 2 Fatal error: Uncaught TypeError: Unsupported operand types: array - array in [no active file]:0
Stack trace:
#0 {main}
thrown in [no active file] on line 0

View file

@ -10,4 +10,5 @@ try {
?> ?>
DONE DONE
--EXPECTF-- --EXPECTF--
Fatal error: Unsupported operand types in %sconstant_expressions_exceptions.inc on line 2 Exception: Unsupported operand types: array - array in %s on line %d
DONE

View file

@ -18,9 +18,9 @@ var_dump($c);
echo "Done\n"; echo "Done\n";
?> ?>
--EXPECTF-- --EXPECTF--
Exception: Unsupported operand types Exception: Unsupported operand types: array / array
Fatal error: Uncaught Error: Unsupported operand types in %s:%d Fatal error: Uncaught TypeError: Unsupported operand types: array / array in %s:%d
Stack trace: Stack trace:
#0 {main} #0 {main}
thrown in %s on line %d thrown in %s on line %d

View file

@ -18,9 +18,9 @@ var_dump($c);
echo "Done\n"; echo "Done\n";
?> ?>
--EXPECTF-- --EXPECTF--
Exception: Unsupported operand types Exception: Unsupported operand types: array * array
Fatal error: Uncaught Error: Unsupported operand types in %s:%d Fatal error: Uncaught TypeError: Unsupported operand types: array * array in %s:%d
Stack trace: Stack trace:
#0 {main} #0 {main}
thrown in %s on line %d thrown in %s on line %d

View file

@ -21,12 +21,12 @@ var_dump($x);
?> ?>
--EXPECT-- --EXPECT--
Unsupported operand types Unsupported operand types: array ** int
array(1) { array(1) {
[0]=> [0]=>
int(0) int(0)
} }
Unsupported operand types Unsupported operand types: array ** array
array(1) { array(1) {
[0]=> [0]=>
int(0) int(0)

View file

@ -153,5 +153,8 @@ if($c === 0) {
$fl = __DIR__ . DIRECTORY_SEPARATOR . 'compare_binary_operands_temp.php'; $fl = __DIR__ . DIRECTORY_SEPARATOR . 'compare_binary_operands_temp.php';
@unlink($fl); @unlink($fl);
?> ?>
--EXPECT-- --EXPECTF--
Failed: 0 Fatal error: Uncaught TypeError: Unsupported operand types: int + array in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d

View file

@ -18,9 +18,9 @@ var_dump($c);
echo "Done\n"; echo "Done\n";
?> ?>
--EXPECTF-- --EXPECTF--
Exception: Unsupported operand types Exception: Unsupported operand types: array - array
Fatal error: Uncaught Error: Unsupported operand types in %s:%d Fatal error: Uncaught TypeError: Unsupported operand types: array - array in %s:%d
Stack trace: Stack trace:
#0 {main} #0 {main}
thrown in %s on line %d thrown in %s on line %d

View file

@ -939,6 +939,16 @@ ZEND_API zend_string* ZEND_FASTCALL zval_try_get_string_func(zval *op) /* {{{ */
} }
/* }}} */ /* }}} */
static ZEND_COLD zend_never_inline void ZEND_FASTCALL zend_binop_error(
const char *operator, zval *op1, zval *op2) {
if (EG(exception)) {
return;
}
zend_type_error("Unsupported operand types: %s %s %s",
zend_get_type_by_const(Z_TYPE_P(op1)), operator, zend_get_type_by_const(Z_TYPE_P(op2)));
}
static zend_never_inline void ZEND_FASTCALL add_function_array(zval *result, zval *op1, zval *op2) /* {{{ */ static zend_never_inline void ZEND_FASTCALL add_function_array(zval *result, zval *op1, zval *op2) /* {{{ */
{ {
if ((result == op1) && (result == op2)) { if ((result == op1) && (result == op2)) {
@ -991,9 +1001,7 @@ static zend_never_inline int ZEND_FASTCALL add_function_slow(zval *result, zval
zval op1_copy, op2_copy; zval op1_copy, op2_copy;
if (UNEXPECTED(zendi_try_convert_scalar_to_number(op1, &op1_copy) == FAILURE) if (UNEXPECTED(zendi_try_convert_scalar_to_number(op1, &op1_copy) == FAILURE)
|| UNEXPECTED(zendi_try_convert_scalar_to_number(op2, &op2_copy) == FAILURE)) { || UNEXPECTED(zendi_try_convert_scalar_to_number(op2, &op2_copy) == FAILURE)) {
if (!EG(exception)) { zend_binop_error("+", op1, op2);
zend_throw_error(NULL, "Unsupported operand types");
}
if (result != op1) { if (result != op1) {
ZVAL_UNDEF(result); ZVAL_UNDEF(result);
} }
@ -1056,9 +1064,7 @@ static zend_never_inline int ZEND_FASTCALL sub_function_slow(zval *result, zval
zval op1_copy, op2_copy; zval op1_copy, op2_copy;
if (UNEXPECTED(zendi_try_convert_scalar_to_number(op1, &op1_copy) == FAILURE) if (UNEXPECTED(zendi_try_convert_scalar_to_number(op1, &op1_copy) == FAILURE)
|| UNEXPECTED(zendi_try_convert_scalar_to_number(op2, &op2_copy) == FAILURE)) { || UNEXPECTED(zendi_try_convert_scalar_to_number(op2, &op2_copy) == FAILURE)) {
if (!EG(exception)) { zend_binop_error("-", op1, op2);
zend_throw_error(NULL, "Unsupported operand types");
}
if (result != op1) { if (result != op1) {
ZVAL_UNDEF(result); ZVAL_UNDEF(result);
} }
@ -1125,9 +1131,7 @@ static zend_never_inline int ZEND_FASTCALL mul_function_slow(zval *result, zval
zval op1_copy, op2_copy; zval op1_copy, op2_copy;
if (UNEXPECTED(zendi_try_convert_scalar_to_number(op1, &op1_copy) == FAILURE) if (UNEXPECTED(zendi_try_convert_scalar_to_number(op1, &op1_copy) == FAILURE)
|| UNEXPECTED(zendi_try_convert_scalar_to_number(op2, &op2_copy) == FAILURE)) { || UNEXPECTED(zendi_try_convert_scalar_to_number(op2, &op2_copy) == FAILURE)) {
if (!EG(exception)) { zend_binop_error("*", op1, op2);
zend_throw_error(NULL, "Unsupported operand types");
}
if (result != op1) { if (result != op1) {
ZVAL_UNDEF(result); ZVAL_UNDEF(result);
} }
@ -1226,9 +1230,7 @@ ZEND_API int ZEND_FASTCALL pow_function(zval *result, zval *op1, zval *op2) /* {
zval op1_copy, op2_copy; zval op1_copy, op2_copy;
if (UNEXPECTED(zendi_try_convert_scalar_to_number(op1, &op1_copy) == FAILURE) if (UNEXPECTED(zendi_try_convert_scalar_to_number(op1, &op1_copy) == FAILURE)
|| UNEXPECTED(zendi_try_convert_scalar_to_number(op2, &op2_copy) == FAILURE)) { || UNEXPECTED(zendi_try_convert_scalar_to_number(op2, &op2_copy) == FAILURE)) {
if (!EG(exception)) { zend_binop_error("**", op1, op2);
zend_throw_error(NULL, "Unsupported operand types");
}
if (result != op1) { if (result != op1) {
ZVAL_UNDEF(result); ZVAL_UNDEF(result);
} }
@ -1306,9 +1308,7 @@ ZEND_API int ZEND_FASTCALL div_function(zval *result, zval *op1, zval *op2) /* {
zval op1_copy, op2_copy; zval op1_copy, op2_copy;
if (UNEXPECTED(zendi_try_convert_scalar_to_number(op1, &op1_copy) == FAILURE) if (UNEXPECTED(zendi_try_convert_scalar_to_number(op1, &op1_copy) == FAILURE)
|| UNEXPECTED(zendi_try_convert_scalar_to_number(op2, &op2_copy) == FAILURE)) { || UNEXPECTED(zendi_try_convert_scalar_to_number(op2, &op2_copy) == FAILURE)) {
if (!EG(exception)) { zend_binop_error("/", op1, op2);
zend_throw_error(NULL, "Unsupported operand types");
}
if (result != op1) { if (result != op1) {
ZVAL_UNDEF(result); ZVAL_UNDEF(result);
} }

View file

@ -156,7 +156,7 @@ Warning: A non-numeric value encountered in %s on line %d
int(0) int(0)
-- Iteration 19 -- -- Iteration 19 --
Unsupported operand types Unsupported operand types: array ** int
-- Iteration 20 -- -- Iteration 20 --

View file

@ -156,7 +156,7 @@ Warning: A non-numeric value encountered in %s on line %d
int(0) int(0)
-- Iteration 19 -- -- Iteration 19 --
Unsupported operand types Unsupported operand types: array ** int
-- Iteration 20 -- -- Iteration 20 --

View file

@ -152,7 +152,7 @@ Warning: A non-numeric value encountered in %s on line %d
float(1) float(1)
-- Iteration 19 -- -- Iteration 19 --
Unsupported operand types Unsupported operand types: float ** array
-- Iteration 20 -- -- Iteration 20 --