Skip to content

Commit 235e152

Browse files
committed
Move object/class redundancy check into union type handling
As such a redundancy can only happen for union types
1 parent 93982b1 commit 235e152

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

Zend/zend_compile.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6456,6 +6456,14 @@ static zend_type zend_compile_typename(
64566456
}
64576457

64586458
free_alloca(type_list, use_heap);
6459+
6460+
uint32_t type_mask = ZEND_TYPE_FULL_MASK(type);
6461+
if ((type_mask & MAY_BE_OBJECT) && (ZEND_TYPE_IS_COMPLEX(type) || (type_mask & MAY_BE_STATIC))) {
6462+
zend_string *type_str = zend_type_to_string(type);
6463+
zend_error_noreturn(E_COMPILE_ERROR,
6464+
"Type %s contains both object and a class type, which is redundant",
6465+
ZSTR_VAL(type_str));
6466+
}
64596467
} else if (ast->kind == ZEND_AST_TYPE_INTERSECTION) {
64606468
zend_ast_list *list = zend_ast_get_list(ast);
64616469
zend_type_list *type_list;
@@ -6516,13 +6524,6 @@ static zend_type zend_compile_typename(
65166524
zend_error_noreturn(E_COMPILE_ERROR, "Type mixed cannot be marked as nullable since mixed already includes null");
65176525
}
65186526

6519-
if ((type_mask & MAY_BE_OBJECT) && (ZEND_TYPE_IS_COMPLEX(type) || (type_mask & MAY_BE_STATIC))) {
6520-
zend_string *type_str = zend_type_to_string(type);
6521-
zend_error_noreturn(E_COMPILE_ERROR,
6522-
"Type %s contains both object and a class type, which is redundant",
6523-
ZSTR_VAL(type_str));
6524-
}
6525-
65266527
if ((type_mask & MAY_BE_NULL) && is_marked_nullable) {
65276528
zend_error_noreturn(E_COMPILE_ERROR, "null cannot be marked as nullable");
65286529
}
@@ -8084,7 +8085,7 @@ static void zend_compile_use(zend_ast *ast) /* {{{ */
80848085

80858086
/* Check that we are not attempting to alias a built-in type */
80868087
if (type == ZEND_SYMBOL_CLASS && zend_is_reserved_class_name(old_name)) {
8087-
zend_error_noreturn(E_COMPILE_ERROR,
8088+
zend_error_noreturn(E_COMPILE_ERROR,
80888089
"Cannot alias '%s' as it is a built-in type", ZSTR_VAL(old_name));
80898090
}
80908091

0 commit comments

Comments
 (0)