Repository navigation
Description
@self-out / @this-out is the only docblock tag in Psalm whose type is parsed without a try { } catch (TypeParseTreeException $e). Any type Psalm cannot parse there escapes as an uncaught throwable during the scan phase, killing the run before a single issue is reported. It cannot be suppressed, and <ignoreFiles> does not help because that skips analysis, not scanning.
laravel/framework v13.32.0 shipped the first widely installed docblock that hits this, so every Psalm 6 and Psalm 7 run against a project resolving laravel/framework >= 13.32 now dies outright. This holds even for projects whose own files never reference Laravel: composer's autoload files entries (Laravel's helpers) pull Collection.php into the scan phase.
Reproducer
repro.php:
<?php declare(strict_types=1);
final class A
{
// 1. parameter-conditional type
/** @phpstan-this-out ($key is null ? static : $this) */
public function s(?int $key): void {}
// 2. plain unparseable type — so this is not only about conditionals
/** @psalm-self-out garbage<<< */
public function t(): void {}
}psalm.xml:
<?xml version="1.0"?>
<psalm errorLevel="1" xmlns="https://getpsalm.org/schema/config">
<projectFiles>
<directory name="."/>
</projectFiles>
</psalm>https://psalm.dev/r/80ce3d4b4a
Actual
Uncaught Psalm\Exception\TypeParseTreeException: Unrecognized template '$key' in .../src/Psalm/Internal/Type/TypeParser.php:342
Stack trace:
#0 .../src/Psalm/Internal/Type/TypeParser.php(281): Psalm\Internal\Type\TypeParser::getTypeFromTree()
#1 .../src/Psalm/Internal/Type/TypeParser.php(158): Psalm\Internal\Type\TypeParser::getTypeFromTree()
#2 .../src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockScanner.php(319): Psalm\Internal\Type\TypeParser::parseTokens()
#3 .../src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php(495): Psalm\Internal\PhpVisitor\Reflector\FunctionLikeDocblockScanner::addDocblockInfo()
...
(Psalm 7.0.0-beta21@5df32a9 crashed due to an uncaught Throwable)
Case 2 crashes the same way, with Unexpected token < from ParseTreeCreator.
Expected
An InvalidDocblock issue, which is what every other tag in the same file already produces:
/** @return ($nope is null ? int : string) */ // InvalidDocblock: Unrecognized template '$nope' in docblock for A::r
/** @return garbage<<< */ // InvalidDocblock: Unexpected token < in docblock for A::u
/** @param-out garbage<<< $x */ // InvalidDocblock: Badly-formatted @param in docblock for A::vNote that @return accepts the parameter-conditional form, because it routes the type through getConditionalSanitizedTypeTokens(), which rewrites $param tokens into generated TGeneratedFromParamN template params. The self_out path parses the raw tokens, so ConditionalTree looks $key up in the template map, does not find it, and throws.
Where
src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockScanner::addDocblockInfo(). Of the eight TypeParser::parseTokens() call sites in that file, the self_out and if_this_is blocks are the only two with no surrounding catch (TypeParseTreeException $e):
$ grep -n "TypeParser::parseTokens\|catch (TypeParseTreeException" src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockScanner.php
257: $storage->global_types[$global['name']] = TypeParser::parseTokens(
266: } catch (TypeParseTreeException $e) {
319: $out_type = TypeParser::parseTokens( <-- self_out, unguarded
336: $out_type = TypeParser::parseTokens( <-- if_this_is, unguarded
614: $namespaced_type = TypeParser::parseTokens(
628: } catch (TypeParseTreeException $e) {
793: $new_param_type = TypeParser::parseTokens(
806: } catch (TypeParseTreeException $e) {
983: $storage->return_type = TypeParser::parseTokens(
1039: } catch (TypeParseTreeException $e) {
1180: $removed_taint = TypeParser::parseTokens(
1197: } catch (TypeParseTreeException $e) {
1387: $out_type = TypeParser::parseTokens(
1398: } catch (TypeParseTreeException $e) {
1451: $template_type = TypeParser::parseTokens(
1462: } catch (TypeParseTreeException $e) {
(Line numbers from 7.0.0-beta21; the structure is the same on 6.x.)
Making the parameter-conditional form actually work looks like a separate, larger change. Degrading to InvalidDocblock would already turn an unrecoverable crash into a suppressible issue.
Versions
- Reproduced on 6.17.2, 7.0.0-beta20 and 7.0.0-beta21. Not a regression in any of them.
- All three tag spellings crash:
@self-out,@psalm-self-out,@phpstan-this-out. - PHP 8.4 and 8.5.
Real-world trigger
laravel/framework v13.32.0, Collection.php:1061, added in laravel/framework#61571:
* @phpstan-this-out ($key is null ? static<TKey|int, TValue> : $this)$key is a declared parameter of prepend(), so the docblock is well formed and PHPStan accepts it. Pinning laravel/framework below v13.32.0 is the only workaround I found.
Possibly related: #10126 (conditional @param-out silently ignored).
Activity
psalm-github-bot commentedon Sep 15, 2026
I found these snippets:
https://psalm.dev/r/80ce3d4b4a
drop Laravel 11 and make the CI matrix install what it tests
ci: hold laravel/framework below 13.32 in the test workflow
ci: hold laravel/framework below 13.32 in the self-analysis workflow too
Adopt `DataFlowNode::getForTaint()` and require Psalm `7.0.0-beta21` (#…
ci: hold laravel/framework below 13.32 until Psalm can parse its docb…
Throw TypeParseTreeException for an is-conditional without a type
Pin InvalidDocblock for a @self-out is-conditional without a type
Support parameter-conditional types in @self-out/@this-out
Report InvalidDocblock instead of crashing on unparseable @self-out/@…
ci: restore the laravel/framework 13.32 pins
ci: drop the laravel/framework 13.32 holds (#1881)