Skip to content

Commit cbbec73

Browse files
committed
Make invalid types in intersection more robust
1 parent d32a1e9 commit cbbec73

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
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 iterable cannot be part of an intersection type in %s on line %d
10+
Fatal error: Type Traversable|array cannot be part of an intersection type in %s on line %d

Zend/zend_compile.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6278,11 +6278,15 @@ static zend_type zend_compile_typename(
62786278
zend_ast *type_ast = list->child[i];
62796279
zend_type single_type = zend_compile_single_typename(type_ast);
62806280

6281-
/* An intersection of standard types cannot exist so invalidate it */
6282-
/* Check for iterable early */
6283-
if (ZEND_TYPE_IS_ITERABLE_FALLBACK(single_type)) {
6284-
zend_error_noreturn(E_COMPILE_ERROR, "Type iterable cannot be part of an intersection type");
6281+
/* An intersection of union types cannot exist so invalidate it
6282+
* Currently only can happen with iterable getting canonicalized to Traversable|array */
6283+
if (ZEND_TYPE_IS_UNION(single_type)) {
6284+
zend_string *standard_type_str = zend_type_to_string(single_type);
6285+
zend_error_noreturn(E_COMPILE_ERROR,
6286+
"Type %s cannot be part of an intersection type", ZSTR_VAL(standard_type_str));
6287+
zend_string_release_ex(standard_type_str, false);
62856288
}
6289+
/* An intersection of standard types cannot exist so invalidate it */
62866290
if (ZEND_TYPE_IS_ONLY_MASK(single_type)) {
62876291
zend_string *standard_type_str = zend_type_to_string(single_type);
62886292
zend_error_noreturn(E_COMPILE_ERROR,

0 commit comments

Comments
 (0)