File tree Expand file tree Collapse file tree 7 files changed +141
-0
lines changed Expand file tree Collapse file tree 7 files changed +141
-0
lines changed Original file line number Diff line number Diff line change @@ -223,6 +223,8 @@ public function dataFileAsserts(): iterable
223
223
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-3915.php ' );
224
224
225
225
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-2378.php ' );
226
+ yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-6294.php ' );
227
+ yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-2580.php ' );
226
228
227
229
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/match-expr.php ' );
228
230
@@ -1255,6 +1257,7 @@ public function dataFileAsserts(): iterable
1255
1257
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/invalid-type-aliases.php ' );
1256
1258
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/asymmetric-properties.php ' );
1257
1259
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-9062.php ' );
1260
+ yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-8092.php ' );
1258
1261
yield from $ this ->gatherAssertTypes (__DIR__ . '/../Rules/Variables/data/bug-9403.php ' );
1259
1262
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/object-shape.php ' );
1260
1263
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/memcache-get.php ' );
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Bug2580 ;
4
+
5
+ use function PHPStan \Testing \assertType ;
6
+
7
+ /**
8
+ * @template T of object
9
+ * @param class-string<T> $typeName
10
+ * @param mixed $value
11
+ */
12
+ function cast ($ value , string $ typeName ): void {
13
+ if (is_object ($ value ) && get_class ($ value ) === $ typeName ) {
14
+ assertType ('T of object (function Bug2580\cast(), argument) ' , $ value );
15
+ }
16
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Bug6294 ;
4
+
5
+ use function PHPStan \Testing \assertType ;
6
+
7
+ class HelloWorld1
8
+ {
9
+ /**
10
+ * @phpstan-param object $object
11
+ * @phpstan-param class-string<HelloWorld1> $classString
12
+ * @phpstan-return HelloWorld1|null
13
+ */
14
+ public function sayHello (object $ object , $ classString ): ?object
15
+ {
16
+ if ($ classString === get_class ($ object )) {
17
+ assertType (HelloWorld1::class, $ object );
18
+
19
+ return $ object ;
20
+ }
21
+
22
+ return null ;
23
+ }
24
+
25
+ /**
26
+ * @phpstan-param HelloWorld1 $object
27
+ * @phpstan-return HelloWorld1|null
28
+ */
29
+ public function sayHello2 (object $ object , object $ object2 ): ?object
30
+ {
31
+ if (get_class ($ object2 ) === get_class ($ object )) {
32
+ assertType (HelloWorld1::class, $ object );
33
+
34
+ return $ object ;
35
+ }
36
+
37
+ return null ;
38
+ }
39
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Bug8092 ;
4
+
5
+ use function PHPStan \Testing \assertType ;
6
+
7
+ interface Generic
8
+ {}
9
+
10
+ class Specific implements Generic
11
+ {}
12
+
13
+ /** @template-covariant T of Generic */
14
+ interface TypeWithGeneric
15
+ {
16
+ /** @return T */
17
+ public function get (): Generic ;
18
+ }
19
+
20
+ /** @implements TypeWithGeneric<Specific> */
21
+ class TypeWithSpecific implements TypeWithGeneric
22
+ {
23
+ public function get (): Specific
24
+ {
25
+ return new Specific ();
26
+ }
27
+ }
28
+
29
+ class HelloWorld
30
+ {
31
+ /** @param TypeWithGeneric<Generic> $type */
32
+ public function test (TypeWithGeneric $ type ): void
33
+ {
34
+ match (get_class ($ type )) {
35
+ TypeWithSpecific::class => assertType (TypeWithSpecific::class, $ type ),
36
+ default => false ,
37
+ };
38
+ }
39
+ }
Original file line number Diff line number Diff line change @@ -507,4 +507,13 @@ public function testBug8614(): void
507
507
$ this ->analyse ([__DIR__ . '/data/bug-8614.php ' ], []);
508
508
}
509
509
510
+ public function testBug8536 (): void
511
+ {
512
+ if (PHP_VERSION_ID < 80100 ) {
513
+ $ this ->markTestSkipped ('Test requires PHP 8.1. ' );
514
+ }
515
+
516
+ $ this ->analyse ([__DIR__ . '/data/bug-8536.php ' ], []);
517
+ }
518
+
510
519
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Bug8536 ;
4
+
5
+ final class A {
6
+ public function __construct (public readonly string $ id ) {}
7
+ }
8
+ final class B {
9
+ public function __construct (public readonly string $ name ) {}
10
+ }
11
+
12
+ class Foo
13
+ {
14
+
15
+ public function getValue (A |B $ obj ): string
16
+ {
17
+ return match (get_class ($ obj )) {
18
+ A::class => $ obj ->id ,
19
+ B::class => $ obj ->name ,
20
+ };
21
+ }
22
+
23
+ }
Original file line number Diff line number Diff line change @@ -901,4 +901,16 @@ public function testConflictingAnnotationProperty(): void
901
901
$ this ->analyse ([__DIR__ . '/data/conflicting-annotation-property.php ' ], []);
902
902
}
903
903
904
+ public function testBug8536 (): void
905
+ {
906
+ if (PHP_VERSION_ID < 80100 ) {
907
+ $ this ->markTestSkipped ('Test requires PHP 8.1. ' );
908
+ }
909
+
910
+ $ this ->checkThisOnly = false ;
911
+ $ this ->checkUnionTypes = true ;
912
+ $ this ->checkDynamicProperties = true ;
913
+ $ this ->analyse ([__DIR__ . '/../Comparison/data/bug-8536.php ' ], []);
914
+ }
915
+
904
916
}
You can’t perform that action at this time.
0 commit comments