You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit ca0a7d6
Browse filesBrowse the repository at this point in the historyBrowse files
Report the witness type of mixed as the given type
When mixed is accepted but its witness type is not, rules now describe the
witness as the given type: `return $c ? $mixed : 1;` in a function returning
string reports "should return string but returns int." from level 7 instead
of "returns mixed" with a tip saying mixed is int on some paths.
RuleLevelHelper::accepts() checks the mixed itself first, so a mixed that
is rejected on its own - explicit mixed from level 9, implicit mixed on
level 10 - is still reported as mixed. RuleLevelHelperAcceptsResult carries
the rejected witness type for the rules describing the given type. The
native extension mirrors it.
Amp-Thread-ID: https://ampcode.com/threads/T-01a237b0-3e9f-77ea-bd9b-d9a06b69686b
Copy file name to clipboardExpand all lines: src/Rules/RuleLevelHelperAcceptsResult.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,7 @@
3
3
namespacePHPStan\Rules;
4
4
5
5
usePHPStan\Turbo\ReferencedByTurboExtension;
6
+
usePHPStan\Type\Type;
6
7
usefunctionarray_merge;
7
8
8
9
/**
@@ -14,10 +15,12 @@ final class RuleLevelHelperAcceptsResult
14
15
15
16
/**
16
17
* @param list<string> $reasons
18
+
* @param Type|null $witnessType Set when the accepted type is a mixed accepted on its own, but its witness type, what some path is known to produce, is not. Rules report it as the given type.
17
19
*/
18
20
publicfunction__construct(
19
21
publicreadonlybool$result,
20
22
publicreadonlyarray$reasons,
23
+
publicreadonly ?Type$witnessType = null,
21
24
)
22
25
{
23
26
}
@@ -27,6 +30,7 @@ public function and(self $other): self
27
30
returnnewself(
28
31
$this->result && $other->result,
29
32
array_merge($this->reasons, $other->reasons),
33
+
$this->witnessType ?? $other->witnessType,
30
34
);
31
35
}
32
36
@@ -40,7 +44,7 @@ public function decorateReasons(callable $cb): self
0 commit comments