Skip to content

Commit 87fd977

Browse files
committed
Invariant T in Type
1 parent 8dad3f3 commit 87fd977

27 files changed

Lines changed: 63 additions & 47 deletions

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ rescaffold:
7373
git add --all 2>/dev/null || true
7474
.PHONY: rescaffold
7575

76+
generate:
77+
$(RUN) php generator/generate.php
78+
$(MAKE) fixer
79+
git add .
80+
.PHONY: generate
81+
7682
var:
7783
mkdir var
7884

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)