File tree 2 files changed +28
-1
lines changed
src/Psalm/Internal/Analyzer/Statements/Expression/Call
2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -1166,7 +1166,7 @@ private static function coerceValueAfterGatekeeperArgument(
1166
1166
}
1167
1167
}
1168
1168
1169
- if ($ context ->inside_conditional ) {
1169
+ if ($ context ->inside_conditional && ! isset ( $ context -> assigned_var_ids [ $ var_id ]) ) {
1170
1170
$ context ->assigned_var_ids [$ var_id ] = false ;
1171
1171
}
1172
1172
Original file line number Diff line number Diff line change @@ -1902,6 +1902,33 @@ function exampleWithOr($value): O {
1902
1902
return $value;
1903
1903
} '
1904
1904
],
1905
+ 'assertVarRedefinedInIfWithOrAndConversion ' => [
1906
+ '<?php
1907
+ interface Convertor {
1908
+ function maybeConvert(string $value): ?SomeObject;
1909
+ }
1910
+
1911
+ interface SomeObject
1912
+ {
1913
+ function isValid(): bool;
1914
+ }
1915
+
1916
+ /**
1917
+ * @param mixed $value
1918
+ */
1919
+ function exampleWithOr(Convertor $convertor, $value): SomeObject
1920
+ {
1921
+ if (
1922
+ !\is_string($value)
1923
+ || ($value = $convertor->maybeConvert($value)) === null
1924
+ || !$value->isValid()
1925
+ ) {
1926
+ throw new Exception();
1927
+ }
1928
+
1929
+ return $value;
1930
+ } '
1931
+ ],
1905
1932
'assertVarRedefinedInIfWithExtraIf ' => [
1906
1933
'<?php
1907
1934
class O {}
You can’t perform that action at this time.
0 commit comments