[ 'code' => 'convert(); $f->test(); ' ], 'withTemplate' => [ 'code' => 'state = $state; } /** * @param string $name * @param mixed $val * @psalm-if-this-is Foo * @return void */ public function set($name, $val) { } /** * @return Foo */ public function freeze() { /** @var Foo */ $f = clone $this; return $f; } } $f = new Foo(new Unfrozen()); $f->set("asd", 10); ' ], 'subclass' => [ 'code' => 'test(); ' ], 'ifThisIsWithSelfAlias' => [ 'code' => ' * @psalm-this-out self<"started"> */ public function start(): void { throw new RuntimeException("???"); } } /** @var App<"idle"> */ $app = new App(); $app->start(); ' ], 'ifThisIsAndThisOutAtTheSameTime' => [ 'code' => ' * @psalm-this-out App<"started"> */ public function start(): void { throw new RuntimeException("???"); } } /** @var App<"idle"> */ $app = new App(); $app->start(); ' ], 'ifThisIsChangeThisTypeInsideMethod' => [ 'code' => ' */ private $items; /** * @param list $items */ public function __construct(array $items) { $this->items = $items; } /** * @psalm-if-this-is ArrayList> * @return ArrayList */ public function compact(): ArrayList { $values = []; foreach ($this->items as $item) { $value = $item->unwrap(); if (null !== $value) { $values[] = $value; } } return new self($values); } } /** @var ArrayList> $list */ $list = new ArrayList([]); $numbers = $list->compact(); ', 'assertions' => [ '$numbers' => 'ArrayList' ], ], 'ifThisIsResolveTemplateParams' => [ 'code' => ' */ private $items; /** * @param list $items */ public function __construct(array $items) { $this->items = $items; } /** * @template A * @template B * @template TOption of Option * @template TEither of Either * * @psalm-if-this-is ArrayList * @return ArrayList */ public function compact(): ArrayList { $values = []; foreach ($this->items as $item) { $value = $item->unwrap(); if (null !== $value) { $values[] = $value; } } return new self($values); } } /** @var ArrayList|Option> $list */ $list = new ArrayList([]); $numbers = $list->compact(); ', 'assertions' => [ '$numbers' => 'ArrayList' ], ], ]; } /** * @return array */ public function providerInvalidCodeParse(): iterable { return [ 'failsWithWrongTemplate1' => [ 'code' => 'data = $data; } /** * @psalm-if-this-is a */ public function test(): void { } } $i = new a("test"); $i->test(); ', 'error_message' => 'IfThisIsMismatch' ], 'failsWithWrongTemplate2' => [ 'code' => 'state = $state; } /** * @param string $name * @param mixed $val * @psalm-if-this-is Foo * @return void */ public function set($name, $val) {} /** * @return Foo */ public function freeze() { /** @var Foo */ $f = clone $this; return $f; } } $f = new Foo(new Unfrozen()); $f->set("asd", 10); $g = $f->freeze(); $g->set("asd", 20); // Fails ', 'error_message' => 'IfThisIsMismatch' ], 'failWithInvalidTemplateConstraint' => [ 'code' => '> * @return ArrayList */ public function compact(): ArrayList { throw new RuntimeException("???"); } } /** @var ArrayList $list */ $list = new ArrayList(); $numbers = $list->compact();', 'error_message' => 'IfThisIsMismatch' ], ]; } }