Skip to content

Commit c801076

Browse files
committed
Fix GH-9556 "iterable" alias "array|Traversable" breaks PHP 8.1 code
Closes GH-9558
1 parent 74ae498 commit c801076

15 files changed

+192
-4
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
A DNF type which contains object is redundant
3+
--FILE--
4+
<?php
5+
6+
interface A {}
7+
interface B {}
8+
9+
function test(): (A&B)|object {}
10+
11+
?>
12+
===DONE===
13+
--EXPECTF--
14+
Fatal error: Type (A&B)|object contains both object and a class type, which is redundant in %s on line %d
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
A DNF type which contains object is redundant 2
3+
--FILE--
4+
<?php
5+
6+
interface A {}
7+
interface B {}
8+
9+
function test(): object|(A&B) {}
10+
11+
?>
12+
===DONE===
13+
--EXPECTF--
14+
Fatal error: Type (A&B)|object contains both object and a class type, which is redundant in %s on line %d
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
iterable type with array should be redundant
3+
--FILE--
4+
<?php
5+
6+
function bar(): array|iterable|null {
7+
return null;
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Duplicate type array is redundant in %s on line %d
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
iterable type with array should be redundant
3+
--FILE--
4+
<?php
5+
6+
function bar(): iterable|array|null {
7+
return null;
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Duplicate type array is redundant in %s on line %d
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
iterable type with second iterable should be redundant
3+
--FILE--
4+
<?php
5+
6+
function bar(): iterable|iterable|null {
7+
return null;
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Duplicate type array is redundant in %s on line %d
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
iterable type with object should NOT be redundant 1
3+
--FILE--
4+
<?php
5+
6+
function bar(): iterable|object|null {
7+
return null;
8+
}
9+
10+
?>
11+
===DONE===
12+
--EXPECT--
13+
===DONE===
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
iterable type with object should NOT be redundant 2
3+
--FILE--
4+
<?php
5+
6+
function bar(): object|iterable|null {
7+
return null;
8+
}
9+
10+
?>
11+
===DONE===
12+
--EXPECT--
13+
===DONE===
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
iterable type with object and class T should be redundant
3+
--FILE--
4+
<?php
5+
6+
function bar(): object|iterable|T|null {
7+
return null;
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Type Traversable|T|object|array|null contains both object and a class type, which is redundant in %s on line %d
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
iterable type with object and class T should be redundant
3+
--FILE--
4+
<?php
5+
6+
function bar(): iterable|object|T|null {
7+
return null;
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Type Traversable|T|object|array|null contains both object and a class type, which is redundant in %s on line %d
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
iterable type with object and class T should be redundant
3+
--FILE--
4+
<?php
5+
6+
function bar(): T|object|iterable|null {
7+
return null;
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Type T|Traversable|object|array|null contains both object and a class type, which is redundant in %s on line %d

0 commit comments

Comments
 (0)