Skip to content

Commit 14b6bb7

Browse files
committed
[skip ci] Get explicit notation working
Have a HT null access somewhere...
1 parent e38380b commit 14b6bb7

23 files changed

+538
-25
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Abstract generic types basic
3+
--FILE--
4+
<?php
5+
6+
interface I<T> {
7+
public function foo(T $param): T;
8+
}
9+
10+
class CS implements I<string> {
11+
public function foo(string $param): string {
12+
return $param . '!';
13+
}
14+
}
15+
16+
class CI implements I<int> {
17+
public function foo(int $param): int {
18+
return $param + 42;
19+
}
20+
}
21+
22+
$cs = new CS();
23+
var_dump($cs->foo("Hello"));
24+
25+
$ci = new CI();
26+
var_dump($ci->foo(5));
27+
28+
?>
29+
--EXPECT--
30+
string(6) "Hello!"
31+
int(47)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Abstract generic type with a constraint
3+
--FILE--
4+
<?php
5+
6+
interface I<T : int|string> {
7+
public function foo(T $param): T;
8+
}
9+
10+
class CS implements I<string> {
11+
public function foo(string $param): string {
12+
return $param . '!';
13+
}
14+
}
15+
16+
class CI implements I<int> {
17+
public function foo(int $param): int {
18+
return $param + 42;
19+
}
20+
}
21+
22+
$cs = new CS();
23+
var_dump($cs->foo("Hello"));
24+
25+
$ci = new CI();
26+
var_dump($ci->foo(5));
27+
28+
?>
29+
--EXPECT--
30+
string(6) "Hello!"
31+
int(47)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Abstract generic type with a constraint that is not satisfied
3+
--FILE--
4+
<?php
5+
6+
interface I<T : int|string> {
7+
public function foo(T $param): T;
8+
}
9+
10+
class C implements I {
11+
public function foo(float $param): float {}
12+
}
13+
14+
?>
15+
--EXPECTF--
16+
Fatal error: Declaration of C::foo(float $param): float must be compatible with I::foo(<T : string|int> $param): <T : string|int> 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+
Abstract generic type cannot be in intersection (simple intersection with class type)
3+
--FILE--
4+
<?php
5+
6+
interface I<T> {
7+
public function foo(T&Traversable $param): T&Traversable;
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Associated type cannot be part of an intersection type 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+
Abstract generic type cannot be in intersection (DNF type)
3+
--FILE--
4+
<?php
5+
6+
interface I<T> {
7+
public function foo(stdClass|(T&Traversable) $param): stdClass|(T&Traversable);
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Associated type cannot be part of an intersection type 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+
Abstract generic type cannot be in union (simple union with built-in type)
3+
--FILE--
4+
<?php
5+
6+
interface I<T> {
7+
public function foo(T|int $param): T|int;
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Associated type cannot be part of a union type 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+
Abstract generic type cannot be in union (simple union with class type)
3+
--FILE--
4+
<?php
5+
6+
interface I<T> {
7+
public function foo(T|stdClass $param): T|stdClass;
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Associated type cannot be part of a union type 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+
Abstract generic type cannot be in union (DNF type)
3+
--FILE--
4+
<?php
5+
6+
interface I<T> {
7+
public function foo(T|(Traversable&Countable) $param): T|(Traversable&Countable);
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Associated type cannot be part of a union type 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+
Abstract generic type cannot be in union (nullable type union with ?)
3+
--FILE--
4+
<?php
5+
6+
interface I<T> {
7+
public function foo(?T $param): ?T;
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Associated type cannot be part of a union type 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+
Abstract generic type cannot be in union (forced allowed null)
3+
--FILE--
4+
<?php
5+
6+
interface I<T> {
7+
public function foo(T $param = null): T;
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Associated type cannot be part of a union type (implicitly nullable due to default null value) in %s on line %d

0 commit comments

Comments
 (0)