File tree Expand file tree Collapse file tree 3 files changed +48
-4
lines changed
tests/type_declarations/intersection_types/variance Expand file tree Collapse file tree 3 files changed +48
-4
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 @@ -583,6 +583,17 @@ static inheritance_status zend_perform_covariant_type_check(
583
583
bool have_unresolved = false;
584
584
585
585
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
+
586
597
/* U_1&...&U_n < V_1&...&V_m if forall V_j. exists U_i. U_i < V_j.
587
598
* U_1&...&U_n < V_1|...|V_m if exists V_j. exists U_i. U_i < V_j.
588
599
* 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(
600
611
proto_ce = ZEND_TYPE_CE (* single_type );
601
612
proto_class_name = proto_ce -> name ;
602
613
} else {
603
- /* standard type */
604
- ZEND_UNREACHABLE ();
605
614
continue ;
606
615
}
607
616
@@ -663,8 +672,6 @@ static inheritance_status zend_perform_covariant_type_check(
663
672
proto_ce = ZEND_TYPE_CE (* single_type );
664
673
proto_class_name = proto_ce -> name ;
665
674
} else {
666
- /* standard type */
667
- ZEND_UNREACHABLE ();
668
675
continue ;
669
676
}
670
677
You can’t perform that action at this time.
0 commit comments