Skip to content

Commit 99139e8

Browse files
committed
Address new review comments
1 parent 2b59df1 commit 99139e8

16 files changed

+73
-52
lines changed

Zend/Optimizer/zend_func_info.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ ZEND_API uint32_t zend_get_func_info(
844844
#endif
845845

846846
ret = zend_get_return_info_from_signature_only(
847-
callee_func, /* script */ NULL, ce, ce_is_instanceof);
847+
callee_func, /* script */ NULL, ce, ce_is_instanceof, /* use_tentative_return_info */ 1);
848848

849849
#if ZEND_DEBUG
850850
if (internal_ret) {
@@ -884,7 +884,7 @@ ZEND_API uint32_t zend_get_func_info(
884884
}
885885
if (!ret) {
886886
ret = zend_get_return_info_from_signature_only(
887-
callee_func, /* TODO: script */ NULL, ce, ce_is_instanceof);
887+
callee_func, /* TODO: script */ NULL, ce, ce_is_instanceof, /* use_tentative_return_info */ 0);
888888
}
889889
}
890890
return ret;

Zend/Optimizer/zend_inference.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4001,9 +4001,12 @@ static int is_recursive_tail_call(const zend_op_array *op_array,
40014001

40024002
uint32_t zend_get_return_info_from_signature_only(
40034003
const zend_function *func, const zend_script *script,
4004-
zend_class_entry **ce, bool *ce_is_instanceof) {
4004+
zend_class_entry **ce, bool *ce_is_instanceof, bool use_tentative_return_info) {
40054005
uint32_t type;
4006-
if (func->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE && !ZEND_ARG_TYPE_IS_TENTATIVE(func->common.arg_info - 1)) {
4006+
if (use_tentative_return_info &&
4007+
func->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE &&
4008+
!ZEND_ARG_TYPE_IS_TENTATIVE(func->common.arg_info - 1)
4009+
) {
40074010
zend_arg_info *ret_info = func->common.arg_info - 1;
40084011
type = zend_fetch_arg_info_type(script, ret_info, ce);
40094012
*ce_is_instanceof = ce != NULL;
@@ -4026,12 +4029,11 @@ ZEND_API void zend_init_func_return_info(
40264029
const zend_op_array *op_array, const zend_script *script, zend_ssa_var_info *ret)
40274030
{
40284031
ZEND_ASSERT((op_array->fn_flags & ZEND_ACC_HAS_RETURN_TYPE));
4029-
ZEND_ASSERT(!ZEND_ARG_TYPE_IS_TENTATIVE(&((zend_function *) op_array)->common.arg_info[-1]));
40304032

40314033
zend_ssa_range tmp_range = {0, 0, 0, 0};
40324034
bool is_instanceof = false;
40334035
ret->type = zend_get_return_info_from_signature_only(
4034-
(zend_function *) op_array, script, &ret->ce, &is_instanceof);
4036+
(zend_function *) op_array, script, &ret->ce, &is_instanceof, /* use_tentative_return_info */ 1);
40354037
ret->is_instanceof = is_instanceof;
40364038
ret->range = tmp_range;
40374039
ret->has_range = 0;

Zend/Optimizer/zend_inference.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ ZEND_API void zend_init_func_return_info(
271271
const zend_op_array *op_array, const zend_script *script, zend_ssa_var_info *ret);
272272
uint32_t zend_get_return_info_from_signature_only(
273273
const zend_function *func, const zend_script *script,
274-
zend_class_entry **ce, bool *ce_is_instanceof);
274+
zend_class_entry **ce, bool *ce_is_instanceof, bool use_tentative_return_info);
275275
void zend_func_return_info(const zend_op_array *op_array,
276276
const zend_script *script,
277277
int recursive,

Zend/Optimizer/zend_optimizer.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,9 +1446,7 @@ ZEND_API int zend_optimize_script(zend_script *script, zend_long optimization_le
14461446
func_info = ZEND_FUNC_INFO(call_graph.op_arrays[i]);
14471447
if (func_info) {
14481448
func_info->call_map = zend_build_call_map(&ctx.arena, func_info, call_graph.op_arrays[i]);
1449-
if ((call_graph.op_arrays[i]->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) &&
1450-
!ZEND_ARG_TYPE_IS_TENTATIVE(&((zend_function *) call_graph.op_arrays[i])->common.arg_info[-1])
1451-
) {
1449+
if (call_graph.op_arrays[i]->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
14521450
zend_init_func_return_info(call_graph.op_arrays[i], script, &func_info->return_info);
14531451
}
14541452
}

Zend/tests/type_declarations/variance/internal_parent/internal_parent.phpt renamed to Zend/tests/type_declarations/variance/internal_parent/unresolvable_inheritance_check_param.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Internal class as parent
2+
Test unresolvable inheritance check due to unavailable parameter type when the parent has a tentative return type.
33
--FILE--
44
<?php
55

Zend/tests/type_declarations/variance/internal_parent/internal_parent2.phpt renamed to Zend/tests/type_declarations/variance/internal_parent/unresolvable_inheritance_check_return.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Internal class as parent
2+
Test unresolvable inheritance check due to unavailable return type when the parent has a tentative return type.
33
--FILE--
44
<?php
55

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Test that the ReturnTypeWillChange attribute cannot target classes
3+
--FILE--
4+
<?php
5+
6+
#[ReturnTypeWillChange]
7+
class Foo
8+
{
9+
}
10+
11+
?>
12+
--EXPECTF--
13+
Fatal error: Attribute "ReturnTypeWillChange" cannot target class (allowed targets: method) in %s on line %d
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
Test that the ReturnTypeWillChange attribute cannot target functions
3+
--FILE--
4+
<?php
5+
6+
#[ReturnTypeWillChange]
7+
function foo() {}
8+
9+
?>
10+
--EXPECTF--
11+
Fatal error: Attribute "ReturnTypeWillChange" cannot target function (allowed targets: method) in %s on line %d
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Test that the ReturnTypeWillChange attribute cannot be used with functions
3+
--FILE--
4+
<?php
5+
6+
class Foo
7+
{
8+
#[ReturnTypeWillChange]
9+
public int $bar;
10+
}
11+
12+
?>
13+
--EXPECTF--
14+
Fatal error: Attribute "ReturnTypeWillChange" cannot target property (allowed targets: method) in %s on line %d

Zend/zend_attributes.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,6 @@ void validate_attribute(zend_attribute *attr, uint32_t target, zend_class_entry
5656
}
5757
}
5858

59-
void validate_return_type_will_change_attribute(zend_attribute *attr, uint32_t target, zend_class_entry *scope)
60-
{
61-
if (target != ZEND_ATTRIBUTE_TARGET_METHOD) {
62-
zend_error(E_COMPILE_ERROR, "Only methods can be marked with #[ReturnTypeWillChange]");
63-
}
64-
}
65-
6659
ZEND_METHOD(Attribute, __construct)
6760
{
6861
zend_long flags = ZEND_ATTRIBUTE_TARGET_ALL;
@@ -293,8 +286,7 @@ void zend_register_attribute_ce(void)
293286
zend_declare_class_constant_long(zend_ce_attribute, ZEND_STRL("IS_REPEATABLE"), ZEND_ATTRIBUTE_IS_REPEATABLE);
294287

295288
zend_ce_return_type_will_change_attribute = register_class_ReturnTypeWillChange();
296-
attr = zend_internal_attribute_register(zend_ce_return_type_will_change_attribute, ZEND_ATTRIBUTE_TARGET_METHOD);
297-
attr->validator = validate_return_type_will_change_attribute;
289+
zend_internal_attribute_register(zend_ce_return_type_will_change_attribute, ZEND_ATTRIBUTE_TARGET_METHOD);
298290
}
299291

300292
void zend_attributes_shutdown(void)

0 commit comments

Comments
 (0)