Skip to content

⭐️ Support star projection * syntax in generic type arguments - #13139

Merged
alies-dev merged 59 commits into
vimeo:star-projectionfrom
alies-dev:alies-dev/11931-star-projection
Nov 21, 2026
Merged

alies-dev merged 59 commits into
vimeo:star-projectionfrom
alies-dev:alies-dev/11931-star-projection

Conversation

@alies-dev

@alies-dev alies-dev commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Psalm rejects PHPStan's star projection Foo<*> with InvalidDocblock and drops the whole annotation, so templates bound through it resolve to never.

Before

<?php
/** @template TValue */
final class Box {}

/**
 * @template TFirst
 * @template TSecond
 */
final class Pair {}

final class Factory {
    /**
     * @template T
     * @param Box<T>|Pair<T, *> $subject
     * @return Box<T>
     */
    public static function make(Box|Pair $subject): Box { // InvalidDocblock: Invalid type '*' in docblock for Factory::make
        throw new Exception();
    }
}

/** @var Box<int> $box */
$box = new Box();
$result = Factory::make($box); // Box<never>

After

    public static function make(Box|Pair $subject): Box { // no issue
$result = Factory::make($box); // Box<int>

Writes through a * are not restricted yet: $box->set(new stdClass) on a Box<*> is accepted, as it is today with the docblock dropped. A follow-up PR makes them never, as PHPStan does. Plugins reading the type_params of a Box<*> see the template's bound.

Fixes #11931
Fixes #11385

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: decreased

Project Memory (MB) Wall (s) Issues Weighted (types) Taint
✅ laravel 1 781 $\color{gray}{\textsf{+0.7\%}}$ 111.4 $\color{gray}{\textsf{-0.3\%}}$ 25 710 $\color{red}{\textsf{+100}}$ $\color{green}{\textsf{-316}}$ 53 049 $\color{green}{\textsf{-464}}$ 682
✅ symfony 3 606 247.2 $\color{gray}{\textsf{+0.1\%}}$ 50 607 98 402 1 528
✅ doctrine-orm 393 21.2 $\color{gray}{\textsf{+0.5\%}}$ 3 480 6 161 0
✅ psl 632 27.1 $\color{gray}{\textsf{+0.3\%}}$ 1 299 5 455 1
✅ phpunit 472 20.4 $\color{gray}{\textsf{+0.5\%}}$ 1 744 3 459 18
✅ php-parser 237 14.1 $\color{gray}{\textsf{+1.2\%}}$ 17 133 21 035 0
✅ tempest 905 36.0 $\color{gray}{\textsf{-0.8\%}}$ 5 043 10 505 252
✅ amphp-amp 61 $\color{gray}{\textsf{+0.1\%}}$ 1.8 $\color{gray}{\textsf{-0.6\%}}$ re-run 29 49 0
✅ webmozarts-assert 288 $\color{gray}{\textsf{+0.1\%}}$ 4.1 $\color{gray}{\textsf{+0.2\%}}$ 577 2 720 0
✅ guzzle-promises 56 $\color{gray}{\textsf{+0.1\%}}$ 1.8 154 427 2
✅ monolog 153 4.9 $\color{gray}{\textsf{+0.2\%}}$ 903 2 403 10
✅ drupal 4 851 203.2 $\color{gray}{\textsf{+5.9\%}}$ 97 526 169 112 583
Total 13 435 $\color{gray}{\textsf{+0.1\%}}$ 693.1 $\color{gray}{\textsf{+1.7\%}}$ 204 205 $\color{red}{\textsf{+100}}$ $\color{green}{\textsf{-316}}$ 372 777 $\color{green}{\textsf{-464}}$ 3 076
How to read this table
  • Memory: Psalm's own peak figure, threads=1. More than +5 % fails, unless the PR changes composer.json.
  • Wall: base and head run on the same runner; ±10 % is noise. Above +20 % warns, never fails. re-run: a reversed second run was taken and the faster kept.
  • Issues: head count over all categories, then $\color{red}{\textsf{+added}}$ $\color{green}{\textsf{-removed}}$ against base.
  • Weighted (types): type issues weighted by error level (levels 1–8 as is, always-errors 10, strictness checks 1). Taint and dead-code issues are not weighed. The projects' own code is pinned and their dependencies resolve identically for base and head, so a change means Psalm reports more, fewer or differently serious issues. A rise is not necessarily a regression.
  • Taint: head count of Tainted* issues, then $\color{orange}{\textsf{+added}}$ $\color{orange}{\textsf{-removed}}$ against base. Both are orange as either direction needs review: more can be new detection or false positives, fewer can be fixed false positives or lost detection.
  • Dead code: head count of unused-code issues, shown only when a run reported some (findUnusedCode). More is red, fewer is green.
  • Total: sum over the projects compared on both sides. Thresholds apply per project, not to the total.
  • Colors: $\color{red}{\textsf{red}}$ past a fail or warn threshold (or more issues), $\color{green}{\textsf{green}}$ an improvement past noise (or fewer issues), $\color{orange}{\textsf{orange}}$ needs review, $\color{gray}{\textsf{gray}}$ noise.
  • Performance: regressed if a head run crashed or timed out or a memory or wall delta is red, else improved if one is green, else unchanged. Its icon is the check result: ❌ fail · ⚠️ warn · ✅ pass; the icon next to each project is that project's result, 💥 = not comparable: base crashed or timed out (counts as ⚠️).
  • Types (heading): direction of the total weighted change, increased · decreased · unchanged. Taint and Dead code (heading): added and removed counts, present only when non-zero. Informational, never fails the check.
✅ laravel: issues +100 −316

Memory 1 768 → 1 781 MB (+0.7 %) · Wall 111.8 → 111.4 s (−0.3 %)

Weighted 53 513 → 53 049 (−464, −0.87 %): L1 −80 · L2 −78 · L3 +26 · L4 −100 · L5 +6 · L6 +9 · always +1

Issue type added removed
ArgumentTypeCoercion 14 0
DocblockTypeContradiction 2 0
InvalidArgument 3 1
InvalidArrayOffset 2 0
InvalidDocblock 0 112
InvalidNullableReturnType 3 0
InvalidPropertyAssignmentValue 3 0
InvalidReturnType 2 0
InvalidStringClass 0 2
LessSpecificImplementedReturnType 3 0
LessSpecificReturnStatement 1 0
MissingParamType 0 73
MissingPropertyType 0 2
MissingReturnType 0 8
MixedArgument 18 32
MixedArgumentTypeCoercion 12 1
MixedArrayAccess 0 3
MixedArrayAssignment 0 1
MixedArrayOffset 0 2
MixedAssignment 0 14
MixedMethodCall 0 50
MixedPropertyAssignment 0 3
MixedPropertyFetch 0 3
MixedReturnStatement 2 3
MoreSpecificImplementedParamType 2 2
MoreSpecificReturnType 0 2
PossiblyInvalidArgument 7 0
PossiblyInvalidCast 1 0
PossiblyInvalidPropertyAssignmentValue 1 0
PossiblyNullArgument 5 0
PossiblyNullArrayAccess 1 0
PropertyTypeCoercion 0 2
RedundantConditionGivenDocblockType 3 0
UndefinedDocblockClass 1 0
UndefinedMagicMethod 12 0
UnsafeInstantiation 2 0

Added (100)

  • src/Illuminate/Auth/Access/Gate.php:667 ArgumentTypeCoercion (error): Argument 1 of Illuminate\Auth\Access\Gate::getPolicyFromAttribute expects class-string, but parent type string provided
  • src/Illuminate/Auth/Access/Gate.php:685 ArgumentTypeCoercion (error): Argument 1 of Illuminate\Auth\Access\Gate::getPolicyFromAttribute expects class-string, but parent type string provided
  • src/Illuminate/Database/Concerns/BuildsQueries.php:500 MixedArgument (error): Argument 1 of Illuminate\Database\Eloquent\Builder::getOriginalColumnNameForCursorPagination cannot be (Illuminate\Database\Eloquent\Builder<TModel:Illuminate\Database\Eloquent\Builder as Illuminate\Database\Eloquent\Mode…
  • src/Illuminate/Database/Concerns/BuildsQueries.php:500 MixedArgument (error): Argument 1 of Illuminate\Database\Query\Builder::getOriginalColumnNameForCursorPagination cannot be Illuminate\Database\Query\Builder&static|mixed, expecting Illuminate\Database\Eloquent\Builder<*>|Illuminate\Database\Que…
  • src/Illuminate/Database/Concerns/BuildsQueries.php:510 MixedArgument (error): Argument 1 of Illuminate\Database\Eloquent\Builder::getOriginalColumnNameForCursorPagination cannot be mixed, expecting Illuminate\Database\Eloquent\Builder<*>|Illuminate\Database\Query\Builder
  • src/Illuminate/Database/Concerns/BuildsQueries.php:510 MixedArgument (error): Argument 1 of Illuminate\Database\Query\Builder::getOriginalColumnNameForCursorPagination cannot be mixed, expecting Illuminate\Database\Eloquent\Builder<*>|Illuminate\Database\Query\Builder
  • src/Illuminate/Database/Concerns/BuildsQueries.php:520 MixedArgument (error): Argument 1 of Illuminate\Database\Eloquent\Builder::getOriginalColumnNameForCursorPagination cannot be (Illuminate\Database\Eloquent\Builder<TModel:Illuminate\Database\Eloquent\Builder as Illuminate\Database\Eloquent\Mode…
  • src/Illuminate/Database/Concerns/BuildsQueries.php:520 MixedArgument (error): Argument 1 of Illuminate\Database\Query\Builder::getOriginalColumnNameForCursorPagination cannot be Illuminate\Database\Query\Builder&static|mixed, expecting Illuminate\Database\Eloquent\Builder<*>|Illuminate\Database\Que…
  • src/Illuminate/Database/Concerns/BuildsQueries.php:535 MixedArgument (error): Argument 1 of Illuminate\Database\Eloquent\Builder::getOriginalColumnNameForCursorPagination cannot be mixed, expecting Illuminate\Database\Eloquent\Builder<*>|Illuminate\Database\Query\Builder
  • src/Illuminate/Database/Concerns/BuildsQueries.php:535 MixedArgument (error): Argument 1 of Illuminate\Database\Query\Builder::getOriginalColumnNameForCursorPagination cannot be mixed, expecting Illuminate\Database\Eloquent\Builder<*>|Illuminate\Database\Query\Builder
  • … and 90 more

Removed (316)

  • src/Illuminate/Auth/Access/Gate.php:695 InvalidDocblock (error): Invalid type 'Illuminate\Auth\Access\*' in docblock for Illuminate\Auth\Access\Gate::getPolicyFromAttribute
  • src/Illuminate/Auth/Access/Gate.php:699 InvalidDocblock (error): Invalid type 'Illuminate\Auth\Access\*' in docblock for Illuminate\Auth\Access\Gate::getPolicyFromAttribute
  • src/Illuminate/Auth/EloquentUserProvider.php:194 MixedArgument (error): Argument 2 of with cannot be mixed, expecting callable[impure](mixed):mixed|null
  • src/Illuminate/Auth/EloquentUserProvider.php:262 MissingReturnType (error): Method Illuminate\Auth\EloquentUserProvider::getQueryCallback does not have a return type
  • src/Illuminate/Auth/EloquentUserProvider.php:262 InvalidDocblock (error): Invalid type 'Illuminate\Auth\*' in docblock for Illuminate\Auth\EloquentUserProvider::getQueryCallback
  • src/Illuminate/Auth/EloquentUserProvider.php:270 InvalidDocblock (error): Invalid type 'Illuminate\Auth\*' in docblock for Illuminate\Auth\EloquentUserProvider::withQuery
  • src/Illuminate/Auth/EloquentUserProvider.php:273 MissingParamType (error): Parameter $queryCallback has no provided type
  • src/Illuminate/Auth/EloquentUserProvider.php:32 MissingPropertyType (error): Property Illuminate\Auth\EloquentUserProvider::$queryCallback does not have a declared type - consider mixed|null
  • src/Illuminate/Auth/EloquentUserProvider.php:32 InvalidDocblock (error): (\Closure(\Illuminate\Database\Eloquent\Builder<*>):mixed)|null is not a valid type (Invalid type 'Illuminate\Auth\*' in src/Illuminate/Auth/EloquentUserProvider.php:27)
  • src/Illuminate/Collections/Traits/TransformsToResourceCollection.php:113 InvalidDocblock (error): Invalid type 'Illuminate\Support\Traits\*' in docblock for Illuminate\Support\Traits\TransformsToResourceCollection::resolveResourceCollectionFromAttribute
  • … and 306 more

head d7438c8 · base 1552477 (merge-base) · workflow run

@alies-dev
alies-dev marked this pull request as draft November 3, 2026 11:12
@alies-dev alies-dev changed the title Support PHPStan's star projection * in generic type arguments [WIP] Support star projection * in generic type arguments Nov 3, 2026
@github-actions github-actions Bot added the release:feature The PR will be included in 'Features' section of the release notes label Nov 3, 2026
@alies-dev
alies-dev force-pushed the alies-dev/11931-star-projection branch 2 times, most recently from 8ac7bee to a46594c Compare November 8, 2026 15:29
@alies-dev alies-dev changed the title [WIP] Support star projection * in generic type arguments Support PHPStan's star projection * in generic type arguments Nov 9, 2026
@alies-dev
alies-dev force-pushed the alies-dev/11931-star-projection branch from a46594c to eb2b1ef Compare November 9, 2026 00:43
…#11931

PHPStan docblocks (Laravel's Relation<TRelated, *, *>, Builder<*>)
made Psalm drop the whole tag and collapse templates to never.

`*` parses as a TStarProjection type argument of a generic object.
Any argument fits it; a `*` argument fits only another `*`, an
argument the container leaves out (`Pair $p`), or a covariant
argument holding the template's bound, and binds a function template
only as that bound. Reading a template bound to `*` gives its bound,
as for a use of the class without the argument. `@extends`,
`@implements`, `@use` and class-string-map values reject it; the
array-like builtins read it as mixed and `class-string<*>` is any
class-string.
@alies-dev
alies-dev force-pushed the alies-dev/11931-star-projection branch from eb2b1ef to e3a5443 Compare November 9, 2026 09:40
@alies-dev
alies-dev force-pushed the alies-dev/11931-star-projection branch from e3a5443 to 4ccb4b1 Compare November 9, 2026 09:45
@alies-dev alies-dev changed the title Support PHPStan's star projection * in generic type arguments Support star projection * syntax in generic type arguments Nov 9, 2026
@alies-dev
alies-dev marked this pull request as ready for review November 9, 2026 10:05
@alies-dev

Copy link
Copy Markdown
Collaborator Author

Split as requested: this PR now covers parsing *, the comparator and reads through the template's bound (236 src lines). Writes through a * position (never, as in PHPStan) follow in a second PR once this one lands. The TClassString change went to #13479 (merged). The description now covers the BC position, why * isn't resolved at parse time, and the Laravel diff; the comparator rejections are pinned by starProjectionIsNotTheConcreteArgument and the cases next to it. PHPStan's own star-projection test cases (Generics/data/typeProjections.php, Rules/Generics/*-template.php, nsrt bug-6732/bug-14466) give the same results here, except the write cases deferred to the second PR.

@alies-dev
alies-dev marked this pull request as draft November 9, 2026 23:11
@alies-dev

Copy link
Copy Markdown
Collaborator Author

Back to draft until the design of how class members read a * argument is settled; the syntax and the comparator rules don't change.

A `*` accepts any argument, so a bare `instanceof` check passed the
containment test without coercion and replaced the star with the
template's bound: `Box<*>` became `Box<object>`, `Pair<int, *>`
narrowed to `Child` became `Child<object>`.
Its shape is not settled yet, so it stays out of the plugin API.
@alies-dev alies-dev changed the title Support star projection * syntax in generic type arguments ⭐️ Support star projection * syntax in generic type arguments Nov 10, 2026
# Conflicts:
#	src/Psalm/Internal/Analyzer/Statements/Expression/Call/ClassTemplateParamCollector.php
#	src/Psalm/Internal/Type/AssertionReconciler.php
#	tests/AnnotationTest.php
#	tests/TypeParseTest.php
…tar-projection

# Conflicts:
#	src/Psalm/Internal/Analyzer/Statements/Expression/Call/ClassTemplateParamCollector.php
#	src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/AtomicMethodCallAnalyzer.php
#	src/Psalm/Internal/Analyzer/Statements/Expression/YieldFromAnalyzer.php


- `TGenericObject::replaceTemplateTypesWithArgTypes()` no longer resolves a new `*` itself (it is impure); the held type is the receiver's bound, which the expander and the comparator resolve again.
- Split `ClassTemplateParamCollector::collect()` into three helpers (ComplexMethod), declare the capabilities of `markStarBindings()` and the test provider, and update the baseline snippet of the changed `getMappedGenericTypeParams()` call.
…ot written vimeo#11931

- Property writes (`$box->prop = $date`, `$box->list[] = $date`) were typed with the star read, so a `Box<DateTime>` was accepted for a `Box<T>` property of a `Box<*>`; only property fetches mark the star now.
- A first-class callable (`$box->merge(...)`) takes its arguments as the bound, and a callable's parameter types (`Closure(Box<T>): void`, at any depth) never produce a `*`.


- Star wins over a left out argument at the same offset, in either order, for a key the combiner merges (`Traversable`).
…ery property read vimeo#11931

- `$box->same(...)` marks star bindings like a call, so its closure returns a `Box<*>`; the closure's parameter types are still the bound (the mark flag is carried to the bounds copy in `getFirstClassCallableType()`).
- `localizePropertyType()` takes `$star_reads` without a default: `get_object_vars()`, `properties-of` and `@psalm-yield` read, class and assignment checks do not.
- Tests: first-class callable return, get_object_vars/properties-of/`@method`/nested property reads, a callable param depth case, and the `@param-out` known gap.
…ad `static<T>` of a covariant class as the bound vimeo#11931

- A template of a class two levels up (`ParentBox::T` is `Middle::U`, which is `Child::V`) is bound to the `*` of a `Child<*>` receiver: method and property reads of `Box<T>` give `Box<*>` again.
- `static<T>` takes the variance of the class of the call, so it reads the bound like `Reader<T>` of a covariant template does.
…meo#11931

- Link Kotlin's star projections instead of attributing `*` to PHPStan, and give Java's unbounded wildcard as the other common name.
…TypeParams() vimeo#11931

- Public `TGenericObject::setTypeParams()` no longer keeps the `*` or left-out marker of a slot whose type it changes, so a plugin that rebuilds the pivot argument of a `Relation<User, *>` gets that type back instead of a `*`.
- An `@internal` `setHeldTypes()` keeps the markers for the internal callers that only refine what a `*` holds (`StarProjection::resolve()`, the expander).
- The plugin test declares `related(): object` so it fails when the provider returns nothing.
…ers the outermost invariant argument vimeo#11931

- A template read from a `Box<*>` into a new `*` slot starts as the `mixed` placeholder, which `resolve()` and the expander turn into the bound of the class the type is read into (`Free<T>` with an unbounded `T` holds `mixed`, not the receiver's `object`); a read property type is expanded for it. Method, `@method`, property and combined reads now print the same `Free<*>` and read the same.
- `@return Box<Box<T>>` read from a `Box<*>` is a `Box<*>`: the outermost invariant argument that mentions a star-bound template becomes the `*`.
- The star bindings move from a flag on the shared `TemplateBound` objects to a `star_bindings` map on `TemplateResult`, merged by `merge()`.
… of the template mapping vimeo#11931

- The type of `@psalm-assert*` is not expanded, so a `*` in it held `mixed`: `getUntemplatedCopy()` and `getMappedGenericTypeParams()` resolve it, and `[...$value]` of a value narrowed to `Collection<*, *>` by `-if-true` or `-if-false` reads the bounds instead of failing on a `mixed` key.
…keep the self-analysis at the base's issues vimeo#11931

- `Relation<*>` with `@mixin Builder<T>` reads `Builder<*>` and `Box<*>` through the mixin instead of the bound (the mixin patch).
- Tests: a mixin read, `offsetGet()`, and the known gaps (wrapped `@implements` argument iterated, callable parameters, composed `@extends` argument); the bare-parameter comments no longer attribute the bare-class change to the write-restriction PR.
- `getMappedGenericTypeParams()` and `getObjectMatchingBase()` are `@psalm-impure` now that the mapping resolves its input; the `getUntemplatedCopy()` resolve is dropped, the comparator and the mapping cover its callers.
…y if every member leaves it out vimeo#11931

- `Box<object>|Box` (an explicit and a bare class, both `Box<object>` as keys) took the left-out marker of the bare member, so it accepted a `Box<*>` that `Box<object>` rejects. The combiner counts the members of a key and the ones leaving an offset out, and keeps `Omitted` only when they are equal.
- A `*` still outweighs the other members at its offset. The unit test covers `*` with a left-out member, two left-out members and a left-out with an explicit member.
…they are applied, and drop the defensive star resolves vimeo#11931

- The types of `@psalm-assert-if-true` and `-if-false` were not expanded, unlike those of `@psalm-assert`, so a `*` in them held `mixed`. `AssertionFinder` now expands a generic object rule type where it applies the rule, next to the class constants it expanded already.
- With that, `StarProjection::resolve()` is no longer called by `GenericTypeComparator`, `getMappedGenericTypeParams()`, `ClassTemplateParamCollector` and `localizePropertyType()`: every `*` they see comes from an expanded type. `getMappedGenericTypeParams()` and `getObjectMatchingBase()` get their capability annotations back. `resolve()` stays for the narrowing, which builds a new `*`. A `*` nested in a non-generic container of an assertion (`list<Reader<*>>`) is still not expanded here.
- Tests: the narrowed types are pinned as `Reader<*>`, with invariant `-if-true`/`-if-false` variants that fail if the `*` is lost, and the `Box<object>|Box` case of the previous commit (a union param of an explicit and a bare class rejects a `Box<*>` like `Box<object>`).
…with setTypeParams() vimeo#11931

- `setTypeParams()` dropped the marker of any slot whose Union was another object; it now drops it only when the new type is not `equals()` to the old one, so a plugin that rebuilds equal arguments keeps a `*`.
- The plugin test rebuilds every argument of a `Relation<Model, *>` as an equal Union; it fails on the previous commit.
…d the self-referencing bound vimeo#11931

- Docblocks of `withoutStarBindings()` and its use in `CallableTrait` say what the bound in a callable parameter is: the known write gap, not a correct read.
- Known-gap test: `($b->setter())(new DateTime())` on a `Box<*>` is accepted until the write-restriction PR.
- `starProjectionStaticOfACovariantArgumentIsTheBound` calls a `takeFoo(Reader<Foo>)` with the `same()` and `staticOf()` results and asserts both read `Reader<Foo>` (`staticOf()` is `Reader<Foo>&static`). It fails without the `static<T>` rule (the type prints `Reader<*>&static`); a false ArgumentTypeCoercion could not be reproduced for a covariant parameter.
- `@template T of Node<*>`: reading `child()` twice gives `Node<*>` each time, which covers the recursion guard of `StarProjection::boundStars()`.
… the nested write gap vimeo#11931

- Removes the rule that took the variance of the class of the call for `static<T>`. In valid code the only difference is how the type prints (`Reader<object>&static` against `Reader<*>&static`): method and function calls, property and list assignments, template inference and `instanceof` give the same issues with and without it, which I compared on two scratch snippets.
- Known-gap test: `$b->nested()->set($box_of_std_class)` on a `Box<*>` with `@return Box<Box<T>>` is accepted until the write-restriction PR.
…its own class vimeo#11931

- `@psalm-assert Box&Countable` on a `Box<*>` gave `Box<*>`: the early return for a `*` narrowed to its own class returned the existing type and dropped the extra types of the asserted one. It adds them to the existing ones now, so the value is a `Box<*>&Countable`.
…n too, and pin the grandchild narrowing vimeo#11931

- `@psalm-assert-if-true list<Reader<*>> $x` left the `*` of the list item unexpanded, so the value did not fit a `list<Reader<Countable>>` parameter although `Reader` is covariant. `expandTypesOfRules()` expands array, keyed array and iterable rule types as well as generic objects, only when it yields a single type.
- Tests: that case, its invariant variant (still a coercion, as it should be), and a guard that a `Box<*>` narrowed by `instanceof` to a grandchild is a `Child<*>` reading the child's bound (the flattened `template_extended_params` already covers two `@extends` levels, so `inferTemplateParamsFromParent()` needed no change).
…alue-of or properties-of vimeo#11931

- `value-of<*>`, `key-of<*>`, `int<*, 5>` and the others were rejected, but with messages about `mixed` ("Untemplated value-of param mixed", "Invalid type mixed as int min boundary"). The parser now throws `The * type argument is only for the type arguments of a class, not of <name>` for them, and so is an InvalidDocblock naming the `*`.
- The invalid-star provider covers the other positions found (`int<5, *>`, `int-mask<*>`, a callable parameter, a closure return, a parenthesised and an intersected argument), which were already rejected with `Invalid type '*'`.
…nd the use statements vimeo#11931

- `\App\Models\Pair<int, *>`, an imported `Pair<int, *>` and an aliased `Couple<int, *>` all give `\App\Models\Pair<int, *>`, so `TypeTokenizer` leaves the `*` alone and resolves the class name next to it. This passes on the previous commit too.
…meo#11931

- Replaces the paragraph listing the rules by one example whose lines end in their result: a `*` fits a concrete argument, another `*`, a left-out argument and a covariant one, but not an invariant `Box<object>` (ArgumentTypeCoercion); `Dependent<int, *>` reads `list<int>`; `class-string<*>` and `list<*>` read `class-string` and `list<mixed>`; `@extends Box<*>` is an InvalidDocblock. I ran the snippet as written and each line gives the issue or type it says.
…les() vimeo#11931

- Self-analysis reported a possibly undefined offset `0` in the previous commit's `expandTypesOfRules()`; the first expanded type is read with `??` and checked, with the same result.
…-assert does vimeo#11931

- `expandTypesOfRules()` expanded only class constants, generic objects, arrays and iterables, so a `*` inside `class-string<Reader<*>>` or `Closure(Reader<*>): void` stayed unexpanded and held `mixed`: `new $x` gave a false ArgumentTypeCoercion, and a template read from the closure parameter gave `mixed`.
- It now expands the atomic of every rule the way CallAnalyzer::applyAssertionsToContext() does for `@psalm-assert`. A union it expands to becomes one IsType per member, as there.
- Tests: `class-string` with `-if-true` and `-if-false`, and a closure parameter. Each fails on the previous commit.
…x drops its extends vimeo#11931

- A type built by a plugin (`Type::parseString()`) is not expanded: probes of function and method return type providers show `Foo::BAR`, `key-of<Foo::ARR>`, `Box<self>` and `static` coming out as written. `plugins_type_system.md` now says to pass such a type through `TypeExpander::expandUnion()`, which also gives a `*` the bound of its template (verified: `readOf()` of the expanded `Reader<*>` reads `Countable`).
- The star projection example reports `MissingTemplateParam` on `StarBox` as well, as the rejected `@extends Box<*>` is dropped. Re-ran the example as written.
…ncestors, callables, `@method` tags and static calls vimeo#11931

- An ancestor's argument that wraps a template the receiver bound to a `*` (`@implements Getter<Box<T>>`, `@implements IteratorAggregate<int, Box<T>>`) reads as `Box<*>`: `TemplateResult::$star_bindings` records the starred type and only the read side (`getLowerBoundsOfReads()`) uses it, so parameters and callable parameters keep `Box<bound>`.
- `Closure::fromCallable()`, callable arrays, first-class callables, `@method` tags (also on interfaces) and static calls through the instance mark the star bindings like a method call.
- `Closure::fromCallable([$any, 'set'])` still takes the bound in its parameter: pinned as a known gap.
@alies-dev
alies-dev merged commit 65f93a2 into vimeo:star-projection Nov 21, 2026
63 checks passed
@alies-dev
alies-dev deleted the alies-dev/11931-star-projection branch November 21, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:feature The PR will be included in 'Features' section of the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support star projection * as a generic type argument (Foo<*>) Psalm tries to read @phpstan tags that it does not support

1 participant