--TEST--
Generics extension: union types inside generic brackets
--DESCRIPTION--
Tests that union types inside generic brackets like Widget are correctly erased.
The entire should be stripped, leaving just Widget.
--SKIPIF--
--FILE--
name = $name;
}
}
class Collection {
public array $items = [];
}
class Either {}
class Result {}
// Function parameters with union types inside generics
function process(Collection $data): void {
echo "processed\n";
}
function handle(Either $value): void {
echo "handled\n";
}
function transform(array $items): void {
echo "array with " . count($items) . " items\n";
}
// Return types with union types inside generics
function getData(): Collection {
return new Collection();
}
function getResult(): Result {
return new Result();
}
function getArray(): array {
return [new Widget('test'), 'hello', 42];
}
// Class methods with union types inside generics
class DataProcessor {
public function process(Collection $data): Either {
return new Either();
}
private function transform(array $values): void {
echo "transformed\n";
}
}
// Properties with union types inside generics
class Container {
public Collection $items;
private array $data = [];
}
// Constructor promotion with union types inside generics
class Service {
public function __construct(
public Collection $items,
private array $values = [],
) {}
}
// Nested generics with union types inside
function complex(array> $data): void {
echo "complex with " . count($data) . " collections\n";
}
function nested(Collection> $items): void {
echo "nested\n";
}
// Test execution
process(new Collection());
handle(new Either());
transform([new Widget('foo'), new Collection()]);
var_dump(getData() instanceof Collection);
var_dump(getResult() instanceof Result);
var_dump(count(getArray()));
$processor = new DataProcessor();
var_dump($processor->process(new Collection()) instanceof Either);
$container = new Container();
$container->items = new Collection();
var_dump($container->items instanceof Collection);
$service = new Service(new Collection());
var_dump($service->items instanceof Collection);
complex([new Collection(), new Collection()]);
nested(new Collection());
echo "All union types inside generics tests passed\n";
?>
--EXPECT--
processed
handled
array with 2 items
bool(true)
bool(true)
int(3)
bool(true)
bool(true)
bool(true)
complex with 2 collections
nested
All union types inside generics tests passed