Skip to content

Commit ca47eeb

Browse files
committed
Test type aliases in used traits
1 parent 15ee323 commit ca47eeb

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

tests/PHPStan/Analyser/data/type-aliases.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,62 @@ public function testIntAlias($int)
158158
assertType('*ERROR*', (new Foo)->recursiveAliasProperty);
159159
assertType('*ERROR*', (new Foo)->circularAliasProperty);
160160

161+
trait FooTrait
162+
{
163+
164+
/**
165+
* @param Test $a
166+
* @return Test
167+
*/
168+
public function doFoo($a)
169+
{
170+
assertType(Test::class, $a);
171+
}
172+
173+
}
174+
175+
/** @phpstan-type Test array{string, int} */
176+
class UsesTrait1
177+
{
178+
179+
use FooTrait;
180+
181+
/** @param Test $a */
182+
public function doBar($a)
183+
{
184+
assertType('array(string, int)', $a);
185+
assertType(Test::class, $this->doFoo());
186+
}
187+
188+
}
189+
190+
/** @phpstan-type Test \stdClass */
191+
class UsesTrait2
192+
{
193+
194+
use FooTrait;
195+
196+
/** @param Test $a */
197+
public function doBar($a)
198+
{
199+
assertType('stdClass', $a);
200+
assertType(Test::class, $this->doFoo());
201+
}
202+
203+
}
204+
205+
class UsesTrait3
206+
{
207+
208+
use FooTrait;
209+
210+
/** @param Test $a */
211+
public function doBar($a)
212+
{
213+
assertType(Test::class, $a);
214+
assertType(Test::class, $this->doFoo());
215+
}
216+
217+
}
218+
161219
}

0 commit comments

Comments
 (0)