Skip to content

Commit b541b24

Browse files
committed
Revert "Support static type in intersection"
Let's not, this points more to a design bug then anything else This reverts commit 611f0e72ef66a6fbd3f438542e50847817f96bfc.
1 parent cff68c9 commit b541b24

File tree

5 files changed

+16
-78
lines changed

5 files changed

+16
-78
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
static type cannot take part in an intersection type
3+
--FILE--
4+
<?php
5+
6+
class A {
7+
public function foo(): static&Iterator {}
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Type static cannot be part of an intersection type in %s on line %d

Zend/tests/type_declarations/intersection_types/redundant_types/duplicate_static_type.phpt

Lines changed: 0 additions & 13 deletions
This file was deleted.

Zend/tests/type_declarations/intersection_types/static_in_intersection.phpt

Lines changed: 0 additions & 41 deletions
This file was deleted.

Zend/zend_compile.c

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,7 @@ zend_string *zend_type_to_string_resolved(zend_type type, zend_class_entry *scop
12471247
name = called_scope->name;
12481248
}
12491249
}
1250-
str = add_type_string(str, name, ZEND_TYPE_IS_INTERSECTION(type));
1250+
str = add_type_string(str, name, /* is_intersection */ false);
12511251
}
12521252
if (type_mask & MAY_BE_CALLABLE) {
12531253
str = add_type_string(str, ZSTR_KNOWN(ZEND_STR_CALLABLE), /* is_intersection */ false);
@@ -6299,9 +6299,8 @@ static zend_type zend_compile_typename(
62996299
} else if (ast->kind == ZEND_AST_TYPE_INTERSECTION) {
63006300
zend_ast_list *list = zend_ast_get_list(ast);
63016301
zend_type_list *type_list;
6302-
unsigned int has_static = 0;
63036302

6304-
// TODO static means that one slot may be unused
6303+
// TODO Is this still true if self/parent are accepted?
63056304
/* Allocate the type list directly on the arena as it must be a type
63066305
* list of the same number of elements as the AST list has children */
63076306
type_list = zend_arena_alloc(&CG(arena), ZEND_TYPE_LIST_SIZE(list->children));
@@ -6314,27 +6313,13 @@ static zend_type zend_compile_typename(
63146313
zend_type single_type = zend_compile_single_typename(type_ast);
63156314

63166315
/* An intersection of standard types cannot exist so invalidate it */
6317-
/* Treat "static" as a class type. */
6318-
if (ZEND_TYPE_IS_ONLY_MASK(single_type) && !(ZEND_TYPE_FULL_MASK(single_type) & MAY_BE_STATIC)) {
6316+
if (ZEND_TYPE_IS_ONLY_MASK(single_type)) {
63196317
zend_string *standard_type_str = zend_type_to_string(single_type);
63206318
zend_error_noreturn(E_COMPILE_ERROR,
63216319
"Type %s cannot be part of an intersection type", ZSTR_VAL(standard_type_str));
63226320
zend_string_release_ex(standard_type_str, false);
63236321
}
63246322

6325-
/* If the type is static */
6326-
if (UNEXPECTED(!ZEND_TYPE_IS_COMPLEX(single_type))) {
6327-
/* Check that static doesn't overlap */
6328-
uint32_t type_mask_overlap = ZEND_TYPE_PURE_MASK(type) & MAY_BE_STATIC;
6329-
if (type_mask_overlap) {
6330-
zend_error_noreturn(E_COMPILE_ERROR, "Duplicate type static is redundant");
6331-
}
6332-
ZEND_TYPE_FULL_MASK(type) |= MAY_BE_STATIC;
6333-
ZEND_TYPE_FULL_MASK(single_type) &= ~_ZEND_TYPE_MAY_BE_MASK;
6334-
has_static = 1;
6335-
continue;
6336-
}
6337-
63386323
/* Add type to the type list */
63396324
type_list->types[type_list->num_types++] = single_type;
63406325

@@ -6349,7 +6334,7 @@ static zend_type zend_compile_typename(
63496334
}
63506335
}
63516336

6352-
ZEND_ASSERT((list->children - has_static) == type_list->num_types);
6337+
ZEND_ASSERT(list->children == type_list->num_types);
63536338

63546339
ZEND_TYPE_SET_LIST(type, type_list);
63556340
ZEND_TYPE_FULL_MASK(type) |= _ZEND_TYPE_ARENA_BIT;

Zend/zend_execute.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,6 @@ static bool zend_check_and_resolve_property_class_type(
845845
zend_type *list_type;
846846

847847
if (ZEND_TYPE_IS_INTERSECTION(info->type)) {
848-
/* Property class can't have static as a type so need to check it here */
849848
ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(info->type), list_type) {
850849
if (ZEND_TYPE_HAS_NAME(*list_type)) {
851850
zend_string *name = ZEND_TYPE_NAME(*list_type);
@@ -1020,10 +1019,6 @@ static zend_always_inline bool zend_check_type_slow(
10201019
if (UNEXPECTED(ZEND_TYPE_HAS_LIST(*type))) {
10211020
zend_type *list_type;
10221021
if (ZEND_TYPE_IS_INTERSECTION(*type)) {
1023-
/* Check if intersection has static inside it */
1024-
if ((ZEND_TYPE_FULL_MASK(*type) & MAY_BE_STATIC) && !zend_value_instanceof_static(arg)) {
1025-
return false;
1026-
}
10271022
ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(*type), list_type) {
10281023
if (HAVE_CACHE_SLOT && *cache_slot) {
10291024
ce = *cache_slot;

0 commit comments

Comments
 (0)