Skip to content

Commit 07c0b65

Browse files
committed
Check NoDiscard together with Deprecated
1 parent c340424 commit 07c0b65

13 files changed

+81
-134
lines changed

Zend/tests/attributes/nodiscard/001.phpt

+11-11
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,24 @@ $closure2();
6363

6464
?>
6565
--EXPECTF--
66-
Warning: (F)The return value of function test() is expected to be consumed in %s on line %d
66+
Warning: (B)The return value of function test() is expected to be consumed in %s on line %d
6767

68-
Warning: (F)The return value of function test2() is expected to be consumed, this is important in %s on line %d
68+
Warning: (B)The return value of function test2() is expected to be consumed, this is important in %s on line %d
6969

70-
Warning: (E)The return value of function test3() is expected to be consumed in %s on line %d
70+
Warning: (B)The return value of function test3() is expected to be consumed in %s on line %d
7171

72-
Warning: (F)The return value of function test() is expected to be consumed in %s on line %d
72+
Warning: (A)The return value of function test() is expected to be consumed in %s on line %d
7373

74-
Warning: (F)The return value of function test() is expected to be consumed in %s on line %d
74+
Warning: (A)The return value of function test() is expected to be consumed in %s on line %d
7575

76-
Warning: (F)The return value of method Clazz::test() is expected to be consumed in %s on line %d
76+
Warning: (A)The return value of method Clazz::test() is expected to be consumed in %s on line %d
7777

78-
Warning: (F)The return value of method Clazz::test2() is expected to be consumed, this is important in %s on line %d
78+
Warning: (A)The return value of method Clazz::test2() is expected to be consumed, this is important in %s on line %d
7979

80-
Warning: (F)The return value of method Clazz::test3() is expected to be consumed in %s on line %d
80+
Warning: (B)The return value of method Clazz::test3() is expected to be consumed in %s on line %d
8181

82-
Warning: (F)The return value of method Clazz::test() is expected to be consumed in %s on line %d
82+
Warning: (A)The return value of method Clazz::test() is expected to be consumed in %s on line %d
8383

84-
Warning: (F)The return value of function {closure:%s:%d}() is expected to be consumed in %s on line %d
84+
Warning: (A)The return value of function {closure:%s:%d}() is expected to be consumed in %s on line %d
8585

86-
Warning: (F)The return value of function {closure:%s:%d}() is expected to be consumed in %s on line %d
86+
Warning: (A)The return value of function {closure:%s:%d}() is expected to be consumed in %s on line %d

Zend/tests/attributes/nodiscard/002.phpt

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ $cls('foo');
3333

3434
?>
3535
--EXPECTF--
36+
Warning: (A)The return value of method Clazz::test() is expected to be consumed in %s on line %d
3637
__call(test)
3738

38-
Warning: (F)The return value of method Clazz::__call() is expected to be consumed in %s on line %d
39+
Warning: (A)The return value of method Clazz::test() is expected to be consumed in %s on line %d
3940
__callStatic(test)
4041

41-
Warning: (F)The return value of method Clazz::__callStatic() is expected to be consumed in %s on line %d
42+
Warning: (A)The return value of method Clazz::__invoke() is expected to be consumed in %s on line %d
4243
__invoke(foo)
4344

44-
Warning: (F)The return value of method Clazz::__invoke() is expected to be consumed in %s on line %d

Zend/tests/attributes/nodiscard/003.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ $cls->test();
1919

2020
?>
2121
--EXPECTF--
22-
Warning: (F)The return value of method Clazz::test() is expected to be consumed in %s on line %d
22+
Warning: (A)The return value of method Clazz::test() is expected to be consumed in %s on line %d

Zend/tests/attributes/nodiscard/005.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ $date->setTimestamp(0);
1212

1313
?>
1414
--EXPECTF--
15-
Warning: (C)The return value of function flock() is expected to be consumed, as locking the stream might have failed in %s on line %d
15+
Warning: (B)The return value of function flock() is expected to be consumed, as locking the stream might have failed in %s on line %d
1616

1717
Warning: (A)The return value of method DateTimeImmutable::setTimestamp() is expected to be consumed, as DateTimeImmutable::setTimestamp() does not modify the object itself in %s on line %d

Zend/tests/attributes/nodiscard/006.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ test();
1717

1818
?>
1919
--EXPECTF--
20-
Warning: (G)The return value of function test() is expected to be consumed in %s on line %d
20+
Warning: (A)The return value of function test() is expected to be consumed in %s on line %d

Zend/tests/attributes/nodiscard/007.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ fclose($f);
1414
?>
1515
--EXPECTF--
1616
<!-- internal enter tmpfile() -->
17-
<!-- internal enter flock() -->
1817
<!-- internal enter NoDiscard::__construct() -->
1918

2019
Warning: (A)The return value of function flock() is expected to be consumed, as locking the stream might have failed in %s on line %d
20+
<!-- internal enter flock() -->
2121
<!-- internal enter fclose() -->

Zend/tests/attributes/nodiscard/008.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ test();
1515
--EXPECTF--
1616
Deprecated: Function test() is deprecated in %s on line %d
1717

18-
Warning: (F)The return value of function test() is expected to be consumed in %s on line %d
18+
Warning: (B)The return value of function test() is expected to be consumed in %s on line %d

Zend/tests/attributes/nodiscard/throwing_error_handler_001.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ try {
3131

3232
?>
3333
--EXPECT--
34-
Caught: (F)The return value of function test() is expected to be consumed
35-
Caught: (F)The return value of function test2() is expected to be consumed
34+
Caught: (B)The return value of function test() is expected to be consumed
35+
Caught: (B)The return value of function test2() is expected to be consumed

Zend/tests/attributes/nodiscard/type_validation_001.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ test();
1212

1313
?>
1414
--EXPECTF--
15-
Warning: (F)The return value of function test() is expected to be consumed, 1234 in %s on line %d
15+
Warning: (B)The return value of function test() is expected to be consumed, 1234 in %s on line %d

Zend/zend_compile.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -3927,15 +3927,15 @@ ZEND_API uint8_t zend_get_call_op(const zend_op *init_op, zend_function *fbc) /*
39273927
ZEND_ASSERT(!(fbc->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE));
39283928
if (fbc->type == ZEND_INTERNAL_FUNCTION && !(CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_FUNCTIONS)) {
39293929
if (init_op->opcode == ZEND_INIT_FCALL && !zend_execute_internal) {
3930-
if (!(fbc->common.fn_flags & ZEND_ACC_DEPRECATED)) {
3930+
if (!(fbc->common.fn_flags & (ZEND_ACC_DEPRECATED|ZEND_ACC_NODISCARD))) {
39313931
return ZEND_DO_ICALL;
39323932
} else {
39333933
return ZEND_DO_FCALL_BY_NAME;
39343934
}
39353935
}
39363936
} else if (!(CG(compiler_options) & ZEND_COMPILE_IGNORE_USER_FUNCTIONS)){
39373937
if (zend_execute_ex == execute_ex) {
3938-
if (!(fbc->common.fn_flags & ZEND_ACC_DEPRECATED)) {
3938+
if (!(fbc->common.fn_flags & (ZEND_ACC_DEPRECATED|ZEND_ACC_NODISCARD))) {
39393939
return ZEND_DO_UCALL;
39403940
} else {
39413941
return ZEND_DO_FCALL_BY_NAME;

Zend/zend_object_handlers.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,7 @@ ZEND_API zend_function *zend_get_call_trampoline_func(const zend_class_entry *ce
16171617
func->fn_flags = ZEND_ACC_CALL_VIA_TRAMPOLINE
16181618
| ZEND_ACC_PUBLIC
16191619
| ZEND_ACC_VARIADIC
1620-
| (fbc->common.fn_flags & (ZEND_ACC_RETURN_REFERENCE|ZEND_ACC_DEPRECATED));
1620+
| (fbc->common.fn_flags & (ZEND_ACC_RETURN_REFERENCE|ZEND_ACC_DEPRECATED|ZEND_ACC_NODISCARD));
16211621
if (fbc->common.attributes) {
16221622
func->attributes = fbc->common.attributes;
16231623
GC_TRY_ADDREF(func->attributes);

Zend/zend_vm_def.h

+14-32
Original file line numberDiff line numberDiff line change
@@ -2936,12 +2936,6 @@ ZEND_VM_HOT_HELPER(zend_leave_helper, ANY, ANY)
29362936
OBJ_RELEASE(ZEND_CLOSURE_OBJECT(EX(func)));
29372937
}
29382938
EG(vm_stack_top) = (zval*)execute_data;
2939-
2940-
if (UNEXPECTED((EX(func)->common.fn_flags & ZEND_ACC_NODISCARD) != 0) && !EX(return_value)) {
2941-
zend_function *fbc = EX(func);
2942-
zend_nodiscard_function("(F)", fbc);
2943-
}
2944-
29452939
execute_data = EX(prev_execute_data);
29462940

29472941
if (UNEXPECTED(EG(exception) != NULL)) {
@@ -2977,11 +2971,6 @@ ZEND_VM_HOT_HELPER(zend_leave_helper, ANY, ANY)
29772971
}
29782972

29792973
old_execute_data = execute_data;
2980-
if (UNEXPECTED((EX(func)->common.fn_flags & ZEND_ACC_NODISCARD) != 0) && !EX(return_value)) {
2981-
zend_function *fbc = EX(func);
2982-
zend_nodiscard_function("(E)", fbc);
2983-
}
2984-
29852974
execute_data = EX(prev_execute_data);
29862975
zend_vm_stack_free_call_frame_ex(call_info, old_execute_data);
29872976

@@ -3001,8 +2990,6 @@ ZEND_VM_HOT_HELPER(zend_leave_helper, ANY, ANY)
30012990
destroy_op_array(&EX(func)->op_array);
30022991
efree_size(EX(func), sizeof(zend_op_array));
30032992
old_execute_data = execute_data;
3004-
ZEND_ASSERT(EX(return_value));
3005-
30062993
execute_data = EG(current_execute_data) = EX(prev_execute_data);
30072994
zend_vm_stack_free_call_frame_ex(call_info, old_execute_data);
30082995

@@ -3023,12 +3010,6 @@ ZEND_VM_HOT_HELPER(zend_leave_helper, ANY, ANY)
30233010
} else {
30243011
if (EXPECTED((call_info & ZEND_CALL_CODE) == 0)) {
30253012
EG(current_execute_data) = EX(prev_execute_data);
3026-
3027-
if (UNEXPECTED((EX(func)->common.fn_flags & ZEND_ACC_NODISCARD) != 0) && !EX(return_value)) {
3028-
zend_function *fbc = EX(func);
3029-
zend_nodiscard_function("(G)", fbc);
3030-
}
3031-
30323013
i_free_compiled_variables(execute_data);
30333014
#ifdef ZEND_PREFER_RELOAD
30343015
call_info = EX_CALL_INFO();
@@ -4127,9 +4108,6 @@ ZEND_VM_HOT_HANDLER(129, ZEND_DO_ICALL, ANY, ANY, SPEC(RETVAL,OBSERVER))
41274108
}
41284109

41294110
if (!RETURN_VALUE_USED(opline)) {
4130-
if (UNEXPECTED((fbc->common.fn_flags & ZEND_ACC_NODISCARD) != 0)) {
4131-
zend_nodiscard_function("(C)", fbc);
4132-
}
41334111
i_zval_ptr_dtor(ret);
41344112
}
41354113

@@ -4178,8 +4156,13 @@ ZEND_VM_HOT_HANDLER(131, ZEND_DO_FCALL_BY_NAME, ANY, ANY, SPEC(RETVAL,OBSERVER))
41784156
SAVE_OPLINE();
41794157
EX(call) = call->prev_execute_data;
41804158

4181-
if (UNEXPECTED((fbc->common.fn_flags & ZEND_ACC_DEPRECATED) != 0)) {
4182-
zend_deprecated_function(fbc);
4159+
if (UNEXPECTED((fbc->common.fn_flags & (ZEND_ACC_DEPRECATED|ZEND_ACC_NODISCARD)) != 0)) {
4160+
if ((fbc->common.fn_flags & ZEND_ACC_DEPRECATED) != 0) {
4161+
zend_deprecated_function(fbc);
4162+
}
4163+
if (EG(exception) == NULL && (fbc->common.fn_flags & ZEND_ACC_NODISCARD) != 0 && !RETURN_VALUE_USED(opline)) {
4164+
zend_nodiscard_function("(B)", fbc);
4165+
}
41834166
if (UNEXPECTED(EG(exception) != NULL)) {
41844167
UNDEF_RESULT();
41854168
if (!RETURN_VALUE_USED(opline)) {
@@ -4259,9 +4242,6 @@ ZEND_VM_C_LABEL(fcall_by_name_end):
42594242
}
42604243

42614244
if (!RETURN_VALUE_USED(opline)) {
4262-
if (UNEXPECTED((fbc->common.fn_flags & ZEND_ACC_NODISCARD) != 0)) {
4263-
zend_nodiscard_function("(B)", fbc);
4264-
}
42654245
i_zval_ptr_dtor(ret);
42664246
}
42674247
}
@@ -4285,8 +4265,13 @@ ZEND_VM_HOT_HANDLER(60, ZEND_DO_FCALL, ANY, ANY, SPEC(RETVAL,OBSERVER))
42854265
SAVE_OPLINE();
42864266
EX(call) = call->prev_execute_data;
42874267

4288-
if (UNEXPECTED((fbc->common.fn_flags & ZEND_ACC_DEPRECATED) != 0)) {
4289-
zend_deprecated_function(fbc);
4268+
if (UNEXPECTED((fbc->common.fn_flags & (ZEND_ACC_DEPRECATED|ZEND_ACC_NODISCARD)) != 0)) {
4269+
if ((fbc->common.fn_flags & ZEND_ACC_DEPRECATED) != 0) {
4270+
zend_deprecated_function(fbc);
4271+
}
4272+
if (EG(exception) == NULL && (fbc->common.fn_flags & ZEND_ACC_NODISCARD) != 0 && !RETURN_VALUE_USED(opline)) {
4273+
zend_nodiscard_function("(A)", fbc);
4274+
}
42904275
if (UNEXPECTED(EG(exception) != NULL)) {
42914276
if (UNEXPECTED(ZEND_CALL_INFO(call) & ZEND_CALL_CLOSURE)) {
42924277
OBJ_RELEASE(ZEND_CLOSURE_OBJECT(call->func));
@@ -4376,9 +4361,6 @@ ZEND_VM_C_LABEL(fcall_end):
43764361
}
43774362

43784363
if (!RETURN_VALUE_USED(opline)) {
4379-
if (UNEXPECTED((fbc->common.fn_flags & ZEND_ACC_NODISCARD) != 0)) {
4380-
zend_nodiscard_function("(A)", fbc);
4381-
}
43824364
i_zval_ptr_dtor(ret);
43834365
}
43844366
}

0 commit comments

Comments
 (0)