Skip to content

Commit 93c705b

Browse files
committed
Invariant generic T in Type
1 parent 1905684 commit 93c705b

27 files changed

Lines changed: 69 additions & 47 deletions

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.8.0] 2026-02-11
9+
10+
### Changed
11+
12+
- **BC Break:** Make generic `T` in `Typhoon\Type` invariant.
13+
814
## [0.7.0] 2025-11-20
915

1016
In this release, we refocus the library: `typhoon/type` now contains only the types necessary for building

generator/Spec/Template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct(
2020
public function declaration(): string
2121
{
2222
return \sprintf(
23-
'@template-covariant %s%s%s',
23+
'@template %s%s%s',
2424
$this->name,
2525
$this->of === null ? '' : ' of ' . $this->of,
2626
$this->default === null ? '' : ' = ' . $this->default,

generator/Spec/Type.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,15 @@ static function (array $matches) use ($typesByName, &$firstType): string {
185185
return "return \$this->{$firstType->name}({$code});";
186186
}
187187

188+
$unionFix = '';
189+
190+
if (str_contains($code, 'UnionT([')) {
191+
$unionFix = ' // @phpstan-ignore argument.type';
192+
}
193+
188194
return <<<PHP
189195
/** @var \\{$firstType->className()} */
190-
static \$reduced = {$code};
196+
static \$reduced = {$code};{$unionFix}
191197
192198
return \$this->{$firstType->name}(\$reduced);
193199
PHP;

src/Type.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
/**
1010
* @api
11-
* @template-covariant T = mixed
11+
* @template T = mixed
1212
*/
1313
interface Type
1414
{

src/Type/ArrayT.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
/**
1414
* @api
15-
* @template-covariant K of array-key = array-key
16-
* @template-covariant V = mixed
15+
* @template K of array-key = array-key
16+
* @template V = mixed
1717
* @implements Type<array<K, V>>
1818
* @codeCoverageIgnore
1919
*/

src/Type/BitmaskT.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
/**
1414
* @api
15-
* @template-covariant T of int = int
15+
* @template T of int = int
1616
* @implements Type<T>
1717
* @codeCoverageIgnore
1818
*/

src/Type/CallableT.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
/**
1414
* @api
15-
* @template-covariant T of callable = callable
15+
* @template T of callable = callable
1616
* @implements Type<T>
1717
* @codeCoverageIgnore
1818
*/

src/Type/ClassConstantMaskT.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
/**
1414
* @api
15-
* @template-covariant T = mixed
15+
* @template T = mixed
1616
* @implements Type<T>
1717
* @codeCoverageIgnore
1818
*/

src/Type/ClassConstantT.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
/**
1414
* @api
15-
* @template-covariant T = mixed
15+
* @template T = mixed
1616
* @implements Type<T>
1717
* @codeCoverageIgnore
1818
*/

src/Type/ClassT.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
/**
1414
* @api
15-
* @template-covariant T of object = object
15+
* @template T of object = object
1616
* @implements Type<class-string<T>>
1717
* @codeCoverageIgnore
1818
*/

0 commit comments

Comments
 (0)