File tree Expand file tree Collapse file tree 3 files changed +48
-2
lines changed
tests/type_declarations/intersection_types/variance Expand file tree Collapse file tree 3 files changed +48
-2
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change @@ -595,6 +595,17 @@ static inheritance_status zend_perform_covariant_type_check(
595
595
bool have_unresolved = false;
596
596
597
597
if (ZEND_TYPE_IS_INTERSECTION (fe_type )) {
598
+ if (proto_type_mask & MAY_BE_OBJECT ) {
599
+ /* TODO We can't just return success here, because the class must be loaded. */
600
+ }
601
+ if (proto_type_mask & MAY_BE_ITERABLE ) {
602
+ /* TODO */
603
+ }
604
+ if (proto_type_mask ) {
605
+ /* An intersection type cannot be a subtype of other builtin types. */
606
+ return INHERITANCE_ERROR ;
607
+ }
608
+
598
609
/* U_1&...&U_n < V_1&...&V_m if forall V_j. exists U_i. U_i < V_j.
599
610
* U_1&...&U_n < V_1|...|V_m if exists V_j. exists U_i. U_i < V_j.
600
611
* As such, we need to iterate over proto_type (V_j) first and use a different
@@ -612,8 +623,6 @@ static inheritance_status zend_perform_covariant_type_check(
612
623
proto_ce = ZEND_TYPE_CE (* single_type );
613
624
proto_class_name = proto_ce -> name ;
614
625
} else {
615
- /* standard type */
616
- ZEND_UNREACHABLE ();
617
626
continue ;
618
627
}
619
628
You can’t perform that action at this time.
0 commit comments