Skip to content

Commit e2ad89c

Browse files
committed
Point to iterable for incompatible type in intersection
1 parent 92b9af8 commit e2ad89c

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Zend/tests/type_declarations/intersection_types/invalid_types/invalid_iterable_type.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ function foo(): iterable&Iterator {}
77

88
?>
99
--EXPECTF--
10-
Fatal error: Type Traversable|array cannot be part of an intersection type in %s on line %d
10+
Fatal error: Type iterable cannot be part of an intersection type in %s on line %d

Zend/zend_compile.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6317,7 +6317,11 @@ static zend_type zend_compile_typename(
63176317
zend_type single_type = zend_compile_single_typename(type_ast);
63186318

63196319
/* An intersection of standard types cannot exist so invalidate it */
6320-
if (ZEND_TYPE_PURE_MASK(single_type)) {
6320+
/* Check for iterable early */
6321+
if (ZEND_TYPE_IS_ITERABLE_FALLBACK(single_type)) {
6322+
zend_error_noreturn(E_COMPILE_ERROR, "Type iterable cannot be part of an intersection type");
6323+
}
6324+
if (ZEND_TYPE_IS_ONLY_MASK(single_type)) {
63216325
zend_string *standard_type_str = zend_type_to_string(single_type);
63226326
zend_error_noreturn(E_COMPILE_ERROR,
63236327
"Type %s cannot be part of an intersection type", ZSTR_VAL(standard_type_str));

0 commit comments

Comments
 (0)