Skip to content

Commit 25c284e

Browse files
committed
Progress on finding where the issues are?
1 parent 25c5fb5 commit 25c284e

File tree

5 files changed

+19
-18
lines changed

5 files changed

+19
-18
lines changed

Zend/tests/type_declarations/composite_types/intersection_and_union_type_combined.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Basic tests for a complex type with an intersection type and union
2+
Test for a complex type with an intersection type and union of a simple type
33
--FILE--
44
<?php
55

Zend/tests/type_declarations/composite_types/union_of_intersection_types.phpt

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Basic tests for a complex type with an intersection type and union
2+
Test for a complex type with an intersection type and union with another intersection
33
--FILE--
44
<?php
55

@@ -12,17 +12,11 @@ class A implements X, Y {}
1212
class B implements W, Z {}
1313
class C {}
1414

15-
function foo1(): X&Y|W&Z {
16-
return new A();
15+
function foo1(X&Y|W&Z $v): X&Y|W&Z {
16+
return $v;
1717
}
18-
function foo2(): W&Z|X&Y {
19-
return new A();
20-
}
21-
function foo3(): X&Y|W&Z {
22-
return new B();
23-
}
24-
function foo4(): W&Z|X&Y {
25-
return new B();
18+
function foo2(W&Z|X&Y $v): W&Z|X&Y {
19+
return $v;
2620
}
2721

2822
function bar1(): X&Y|W&Z {
@@ -32,13 +26,16 @@ function bar2(): W&Z|X&Y {
3226
return new C();
3327
}
3428

35-
$o = foo1();
29+
$a = new A();
30+
$b = new B();
31+
32+
$o = foo1($a);
3633
var_dump($o);
37-
$o = foo2();
34+
$o = foo2($a);
3835
var_dump($o);
39-
$o = foo3();
36+
$o = foo1($b);
4037
var_dump($o);
41-
$o = foo4();
38+
$o = foo2($b);
4239
var_dump($o);
4340

4441
try {

Zend/zend_compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6283,7 +6283,7 @@ static zend_type zend_compile_typename(
62836283
if (type_ast->kind == ZEND_AST_TYPE_INTERSECTION) {
62846284
if (type_list->num_types == 0) {
62856285
/* The first class type can be stored directly as the type ptr payload. */
6286-
if (ZEND_TYPE_IS_COMPLEX(type)) {
6286+
if (ZEND_TYPE_HAS_NAME(type) || ZEND_TYPE_HAS_CE(type) || ZEND_TYPE_HAS_CE_CACHE(type)) {
62876287
/* Switch from single name to name list. */
62886288
type_list->num_types = 1;
62896289
type_list->types[0] = type;

Zend/zend_execute.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,7 @@ static bool zend_check_intersection_type(zend_type_list *intersection_type_list,
10741074
return true;
10751075
}
10761076

1077+
/* TODO Need to rewind cache slot pointer? */
10771078
static zend_always_inline bool zend_check_type_slow(
10781079
zend_type *type, zval *arg, zend_reference *ref, void **cache_slot, zend_class_entry *scope,
10791080
bool is_return_type, bool is_internal)
@@ -1087,6 +1088,7 @@ static zend_always_inline bool zend_check_type_slow(
10871088
/* Type is only an intersection type */
10881089
if (ZEND_TYPE_IS_INTERSECTION(*type)) {
10891090
ZEND_ASSERT(!ZEND_TYPE_IS_UNION(*type));
1091+
ZEND_ASSERT(Z_TYPE_P(arg) == IS_OBJECT);
10901092
return zend_check_intersection_type(ZEND_TYPE_LIST(*type), Z_OBJ_P(arg), cache_slot, scope);
10911093
}
10921094

@@ -1095,6 +1097,7 @@ static zend_always_inline bool zend_check_type_slow(
10951097
ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(*type), list_type) {
10961098
/* Type is an intersection */
10971099
if (UNEXPECTED(ZEND_TYPE_IS_INTERSECTION(*list_type))) {
1100+
ZEND_ASSERT(Z_TYPE_P(arg) == IS_OBJECT);
10981101
if (zend_check_intersection_type(ZEND_TYPE_LIST(*list_type), Z_OBJ_P(arg), cache_slot, scope)) {
10991102
return true;
11001103
}

Zend/zend_language_parser.y

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
6666
%right T_COALESCE
6767
%left T_BOOLEAN_OR
6868
%left T_BOOLEAN_AND
69+
%left T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG
6970
%left '|'
7071
%left '^'
71-
%left T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG
72+
%left T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG
7273
%nonassoc T_IS_EQUAL T_IS_NOT_EQUAL T_IS_IDENTICAL T_IS_NOT_IDENTICAL T_SPACESHIP
7374
%nonassoc '<' T_IS_SMALLER_OR_EQUAL '>' T_IS_GREATER_OR_EQUAL
7475
%left '.'

0 commit comments

Comments
 (0)