Skip to content

Commit 85116bd

Browse files
committed
Add failing test
1 parent 3d2a393 commit 85116bd

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Replacing int type with intersection type
3+
--FILE--
4+
<?php
5+
6+
interface X {}
7+
interface Y {}
8+
9+
class Test {
10+
function method(): int {}
11+
}
12+
class Test2 extends Test {
13+
function method(): X&Y {}
14+
}
15+
16+
?>
17+
--EXPECTF--
18+
Fatal error: Declaration of Test2::method(): X&Y must be compatible with Test::method(): int in %s on line %d
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Replacing object type with intersection type
3+
--FILE--
4+
<?php
5+
6+
interface X {}
7+
interface Y {}
8+
9+
class Test {
10+
function method(): object {}
11+
}
12+
class Test2 extends Test {
13+
function method(): X&Y {}
14+
}
15+
16+
?>
17+
===DONE===
18+
--EXPECTF--
19+
TODO

Zend/zend_inheritance.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,17 @@ static inheritance_status zend_perform_covariant_type_check(
583583
bool have_unresolved = false;
584584

585585
if (ZEND_TYPE_IS_INTERSECTION(fe_type)) {
586+
if (proto_type_mask & MAY_BE_OBJECT) {
587+
/* TODO We can't just return success here, because the class must be loaded. */
588+
}
589+
if (proto_type_mask & MAY_BE_ITERABLE) {
590+
/* TODO */
591+
}
592+
if (proto_type_mask) {
593+
/* An intersection type cannot be a subtype of other builtin types. */
594+
return INHERITANCE_ERROR;
595+
}
596+
586597
/* U_1&...&U_n < V_1&...&V_m if forall V_j. exists U_i. U_i < V_j.
587598
* U_1&...&U_n < V_1|...|V_m if exists V_j. exists U_i. U_i < V_j.
588599
* As such, we need to iterate over proto_type (V_j) first and use a different
@@ -600,8 +611,6 @@ static inheritance_status zend_perform_covariant_type_check(
600611
proto_ce = ZEND_TYPE_CE(*single_type);
601612
proto_class_name = proto_ce->name;
602613
} else {
603-
/* standard type */
604-
ZEND_UNREACHABLE();
605614
continue;
606615
}
607616

@@ -663,8 +672,6 @@ static inheritance_status zend_perform_covariant_type_check(
663672
proto_ce = ZEND_TYPE_CE(*single_type);
664673
proto_class_name = proto_ce->name;
665674
} else {
666-
/* standard type */
667-
ZEND_UNREACHABLE();
668675
continue;
669676
}
670677

0 commit comments

Comments
 (0)