Skip to content

Commit 42cbace

Browse files
committed
Fix range inference since "proper-range-semantics" RFC
* Arrays returned from range are never empty * When step is a double value representable by a long, it is coerced implicitly. As such, passing a double step no longer guarantees that the result is a non-int array. Closes GH-13166
1 parent 47454cb commit 42cbace

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ PHP NEWS
1717

1818
- Opcache:
1919
. Fixed bug GH-13145 (strtok() is not comptime). (ilutov)
20+
. Fixed type inference of range(). (ilutov)
2021

2122
- OpenSSL:
2223
. Fixed LibreSSL undefined reference when OPENSSL_NO_ENGINE not set.

Zend/Optimizer/zend_func_info.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static uint32_t zend_range_info(const zend_call_info *call_info, const zend_ssa
6161
uint32_t t2 = _ssa_op1_info(op_array, ssa, call_info->arg_info[1].opline,
6262
&ssa->ops[call_info->arg_info[1].opline - op_array->opcodes]);
6363
uint32_t t3 = 0;
64-
uint32_t tmp = MAY_BE_RC1 | MAY_BE_ARRAY | MAY_BE_ARRAY_EMPTY;
64+
uint32_t tmp = MAY_BE_RC1 | MAY_BE_ARRAY;
6565

6666
if (call_info->num_args == 3) {
6767
t3 = _ssa_op1_info(op_array, ssa, call_info->arg_info[2].opline,
@@ -77,9 +77,7 @@ static uint32_t zend_range_info(const zend_call_info *call_info, const zend_ssa
7777
}
7878
if ((t1 & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE))
7979
&& (t2 & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE))) {
80-
if ((t3 & MAY_BE_ANY) != MAY_BE_DOUBLE) {
81-
tmp |= MAY_BE_ARRAY_OF_LONG;
82-
}
80+
tmp |= MAY_BE_ARRAY_OF_LONG;
8381
}
8482
if (tmp & MAY_BE_ARRAY_OF_ANY) {
8583
tmp |= MAY_BE_ARRAY_PACKED;

0 commit comments

Comments
 (0)