File tree Expand file tree Collapse file tree 5 files changed +69
-2
lines changed
Expand file tree Collapse file tree 5 files changed +69
-2
lines changed Original file line number Diff line number Diff line change 11<?php
22
3+ /**
4+ * @throws RuntimeException
5+ */
36function start (null |string $ id ): void
47{
58 $ id ?? throw new RuntimeException ();
Original file line number Diff line number Diff line change 88 */
99function x ($ data ): void
1010{
11- $ data ['currency ' ] ?? throw new \InvalidArgumentException ('Currency is required. ' ); // @mago-expect analysis: unused-statement
11+ $ data ['currency ' ] ?? throw new \InvalidArgumentException ('Currency is required. ' );
1212 accept_string ($ data ['currency ' ]);
1313}
1414
15- function accept_string (string $ _s ): void {}
15+ function accept_string (string $ _s ): void
16+ {
17+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ interface TestInterface
4+ {
5+ public function test (): void ;
6+ }
7+
8+ /**
9+ * @template T of TestInterface|null
10+ */
11+ class Test
12+ {
13+ /**
14+ * @psalm-param T $value
15+ */
16+ public function __construct (
17+ public TestInterface |null $ value ,
18+ ) {}
19+
20+ public function getValue (): null |TestInterface
21+ {
22+ return $ this ->value ;
23+ }
24+
25+ public function getValue2 (): TestInterface
26+ {
27+ if ($ this ->value === null ) {
28+ exit (1 );
29+ }
30+
31+ return $ this ->value ;
32+ }
33+
34+ public function getValue3 (): TestInterface
35+ {
36+ return $ this ->value ?? exit (1 );
37+ }
38+ }
39+
40+ /**
41+ * @template T of string|null
42+ */
43+ class ScalarTest
44+ {
45+ /**
46+ * @param T $value
47+ */
48+ public function __construct (
49+ public string |null $ value ,
50+ ) {}
51+
52+ public function getValue (): string
53+ {
54+ if ($ this ->value === null ) {
55+ return 'default ' ;
56+ }
57+
58+ return $ this ->value ;
59+ }
60+ }
Original file line number Diff line number Diff line change @@ -330,6 +330,7 @@ test_case!(type_assert);
330330test_case ! ( string_callable_template_inference) ;
331331test_case ! ( clear_narrowed_prop_after_call) ;
332332test_case ! ( binary_throw_used) ;
333+ test_case ! ( template_null_comparison) ;
333334
334335// Github Issues
335336test_case ! ( issue_659) ;
Original file line number Diff line number Diff line change @@ -796,6 +796,7 @@ impl TUnion {
796796 pub fn is_nullable ( & self ) -> bool {
797797 self . types . iter ( ) . any ( |t| match t {
798798 TAtomic :: Null => self . types . len ( ) >= 2 ,
799+ TAtomic :: GenericParameter ( param) => param. constraint . is_nullable ( ) ,
799800 _ => false ,
800801 } )
801802 }
You can’t perform that action at this time.
0 commit comments