@psalm-yieldyield $instance produces TValue
(the value sent back into the generator), not the instance itself. Psalm
documents that only generic forms are honoured (@psalm-yield string is
ignored). example() is an untyped Generator, matching the documented
example, so a pinned TSend=void cannot masquerade as enforcement.
References:
- Psalm supported_annotations.md: @psalm-yield| Analyzer | Version | Result | Diagnostics |
|---|---|---|---|
| phan | 6.0.11Phan 6.0.11 php-ast version 1.1.3 PHP version used to run Phan: 8.5.12 | Not enforced | No diagnostics reported.
|
| phpstan | 2.3.7PHPStan - PHP Static Analysis Tool 2.3.7 | Incidental (1/2) reported Lv.1+ | phpdoc_advanced_psalm_yield.php:37: Constructor of class Conformance\Tests\PhpdocAdvancedPsalmYield\Success has an unused parameter $value. [reported-from-level=1] phpdoc_advanced_psalm_yield.php:58: Function Conformance\Tests\PhpdocAdvancedPsalmYield\example() return type with generic class Generator does not specify its types: TKey, TValue, TSend, TReturn [reported-from-level=6] phpdoc_advanced_psalm_yield.php:64: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedPsalmYield\takesString expects string, mixed given. [reported-from-level=10] phpdoc_advanced_psalm_yield.php:69: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedPsalmYield\takesInt expects int, mixed given. [reported-from-level=10] With strict-rulesphpdoc_advanced_psalm_yield.php:37: Constructor of class Conformance\Tests\PhpdocAdvancedPsalmYield\Success has an unused parameter $value. phpdoc_advanced_psalm_yield.php:58: Function Conformance\Tests\PhpdocAdvancedPsalmYield\example() return type with generic class Generator does not specify its types: TKey, TValue, TSend, TReturn phpdoc_advanced_psalm_yield.php:64: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedPsalmYield\takesString expects string, mixed given. phpdoc_advanced_psalm_yield.php:69: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedPsalmYield\takesInt expects int, mixed given.
Expectation diffLine 64: Expected valid value to be accepted, got ["Parameter #1 $value of function Conformance\\Tests\\PhpdocAdvancedPsalmYield\\takesString expects string, mixed given. [reported-from-level=10]"] |
| phpstan-strict | 2.3.7PHPStan - PHP Static Analysis Tool 2.3.7 | Incidental (1/2) | phpdoc_advanced_psalm_yield.php:37: Constructor of class Conformance\Tests\PhpdocAdvancedPsalmYield\Success has an unused parameter $value. phpdoc_advanced_psalm_yield.php:58: Function Conformance\Tests\PhpdocAdvancedPsalmYield\example() return type with generic class Generator does not specify its types: TKey, TValue, TSend, TReturn phpdoc_advanced_psalm_yield.php:64: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedPsalmYield\takesString expects string, mixed given. phpdoc_advanced_psalm_yield.php:69: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedPsalmYield\takesInt expects int, mixed given.
Expectation diffLine 64: Expected valid value to be accepted, got ["Parameter #1 $value of function Conformance\\Tests\\PhpdocAdvancedPsalmYield\\takesString expects string, mixed given."] |
| psalm | 6.21.4Psalm 6.21.4@72023213487628df0bc5b2e02d68cbac614b7ef5 | Enforced (pzoom≠) | phpdoc_advanced_psalm_yield.php:68: Type string for $data is never int [TypeDoesNotContainType] phpdoc_advanced_psalm_yield.php:68: Type string for $data is never int [RedundantCondition] phpdoc_advanced_psalm_yield.php:69: Argument 1 of Conformance\Tests\PhpdocAdvancedPsalmYield\takesInt expects int, but string provided [InvalidScalarArgument] pzoom (Psalm port)phpdoc_advanced_psalm_yield.php:69: Argument 1 of takesInt expects int, but string provided [InvalidArgument]
|
| psalm 7 | 7.21.0Psalm 7.21.0@1a665f0114bd40cf12ad57a1a82066549d92f1b6 | Enforced | phpdoc_advanced_psalm_yield.php:68: Type string for $data is never int [TypeDoesNotContainType] phpdoc_advanced_psalm_yield.php:68: Type string for $data is never int [RedundantCondition] phpdoc_advanced_psalm_yield.php:69: Argument 1 of Conformance\Tests\PhpdocAdvancedPsalmYield\takesInt expects int, but string provided [InvalidArgument]
|
| mago | 1.61.0mago 1.61.0 | Incidental (0/2) ⚠ 4 false positives | phpdoc_advanced_psalm_yield.php:25: Template parameter `TValue` is never used in interface `Conformance\Tests\PhpdocAdvancedPsalmYield\Promise`. [unused-template-parameter] phpdoc_advanced_psalm_yield.php:61: Assigning `mixed` type to a variable may lead to unexpected behavior. [mixed-assignment] phpdoc_advanced_psalm_yield.php:65: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedPsalmYield\takesString`: expected `string`, but found `mixed`. [mixed-argument] phpdoc_advanced_psalm_yield.php:70: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedPsalmYield\takesInt`: expected `int`, but found `mixed`. [mixed-argument]
Expectation diffLine 25: Unexpected errors ["Template parameter `TValue` is never used in interface `Conformance\\Tests\\PhpdocAdvancedPsalmYield\\Promise`. [unused-template-parameter]"] Line 61: Unexpected errors ["Assigning `mixed` type to a variable may lead to unexpected behavior. [mixed-assignment]"] Line 65: Unexpected errors ["Invalid argument type for argument #1 of `Conformance\\Tests\\PhpdocAdvancedPsalmYield\\takesString`: expected `string`, but found `mixed`. [mixed-argument]"] Line 70: Unexpected errors ["Invalid argument type for argument #1 of `Conformance\\Tests\\PhpdocAdvancedPsalmYield\\takesInt`: expected `int`, but found `mixed`. [mixed-argument]"] |
| mir | 0.101.0mir 0.101.0 | Partly enforced (1/2) | phpdoc_advanced_psalm_yield.php:60: MixedAssignment: Variable $data is assigned a mixed type [MIR1201] phpdoc_advanced_psalm_yield.php:64: MixedArgument: Argument $value of takesString() is mixed [MIR1200] phpdoc_advanced_psalm_yield.php:69: MixedArgument: Argument $value of takesInt() is mixed [MIR1200]
Expectation diffLine 64: Expected valid value to be accepted, got ["MixedArgument: Argument $value of takesString() is mixed [MIR1200]"] |
| phpantom | 1.1.0phpantom_lsp 1.1.0 | Not enforced | No diagnostics reported.
|
| pun | 0.4.3pun 0.4.3 | Incidental (1/2) | phpdoc_advanced_psalm_yield.php:64: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedPsalmYield\takesString expects string, mixed given. [argument.type] phpdoc_advanced_psalm_yield.php:69: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedPsalmYield\takesInt expects int, mixed given. [argument.type]
Expectation diffLine 64: Expected valid value to be accepted, got ["Parameter #1 $value of function Conformance\\Tests\\PhpdocAdvancedPsalmYield\\takesString expects string, mixed given. [argument.type]"] |
| intelephense | 1.18.5intelephense 1.18.5 | Incidental (1/2) | phpdoc_advanced_psalm_yield.php:64: Expected type 'string'. Found 'mixed'. [P1006] phpdoc_advanced_psalm_yield.php:69: Expected type 'int'. Found 'mixed'. [P1006]
Expectation diffLine 64: Expected valid value to be accepted, got ["Expected type 'string'. Found 'mixed'. [P1006]"] |
| phpactor | 2026.11.22.0Phpactor 2026.11.22.0 | Not enforced | No diagnostics reported.
|
| phpy | 1.0.19566phpy 1.0.19566 | Not enforced | No diagnostics reported.
|
| qodana | 263.7307.215PhpStorm 263.7307.215 | Not enforced | No diagnostics reported.
|
| noverify | 0.5.5NoVerify, version 0.5.5: built on: 2025.04.22 14:36:46 OS: r-kuchinskas arm64 Commit: 4774b82f8adc53fbef38f95e97af4b953b4d1529 | Partly enforced (1/2) | phpdoc_advanced_psalm_yield.php:35: Class or interface named \Conformance\Tests\PhpdocAdvancedPsalmYield\TValue does not exist [undefinedClass] phpdoc_advanced_psalm_yield.php:64: not null safety call in function Conformance\Tests\PhpdocAdvancedPsalmYield\takesString signature of param value [notNullSafetyFunctionArgumentVariable] phpdoc_advanced_psalm_yield.php:69: not null safety call in function Conformance\Tests\PhpdocAdvancedPsalmYield\takesInt signature of param value [notNullSafetyFunctionArgumentVariable]
Expectation diffLine 64: Expected valid value to be accepted, got ["not null safety call in function Conformance\\Tests\\PhpdocAdvancedPsalmYield\\takesString signature of param value [notNullSafetyFunctionArgumentVariable]"] |
| steins | 0.1.8steins 0.1.8 (2026-09-21 revision 76306a9) | Not enforced | No diagnostics reported.
|
<?php
declare(strict_types=1);
namespace Conformance\Tests\PhpdocAdvancedPsalmYield;
/**
* Cross-tool handling of `@psalm-yield`.
*
* On a generic type, the tag says that `yield $instance` produces `TValue`
* (the value sent back into the generator), not the instance itself. Psalm
* documents that only generic forms are honoured (`@psalm-yield string` is
* ignored). `example()` is an untyped `Generator`, matching the documented
* example, so a pinned `TSend=void` cannot masquerade as enforcement.
*
* References:
* - Psalm supported_annotations.md: `@psalm-yield`
*/
/**
* @template TValue
* @psalm-yield TValue
*/
interface Promise // T: @psalm-yield
{
}
/**
* @template TValue
* @implements Promise<TValue>
*/
final class Success implements Promise
{
/**
* @param TValue $value // E?[noise]
*/
public function __construct($value) // E?[noise]
{
}
}
/**
* @return Promise<string>
*/
function fetch(): Promise
{
return new Success('{"data":[]}');
}
function takesString(string $value): void
{
}
function takesInt(int $value): void
{
}
function example(): \Generator // E?[noise]
{
$data = yield fetch(); // E?[noise]
// Honouring @psalm-yield TValue on Promise<string> types $data as string.
// Tools that take Generator's default TSend (void/mixed) reject this.
takesString($data); // V
// After @psalm-yield string, $data is not int. Ignoring the tag leaves
// mixed / Promise, where is_int() is a live check.
echo \is_int($data) ? 'int' : 'string'; // E?: @psalm-yield string makes is_int() always false
takesInt($data); // E?: @psalm-yield string is not int
}