Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Analyser/TypeSpecifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ public function specifyTypesInCondition(
);
} elseif (
$expr instanceof Expr\Cast\String_
|| $expr instanceof Expr\Cast\Double
|| $expr instanceof Expr\Cast\Int_
|| $expr instanceof Expr\Cast\Bool_
) {
Expand Down
21 changes: 21 additions & 0 deletions tests/PHPStan/Analyser/nsrt/narrow-cast.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,24 @@ function castInt($x, string $s, bool $b) {
assertType('string', $s);
}
}

/** @param int<-5, 5> $x */
function castFloat($x, string $s, bool $b) {
if ((float) $x) {
assertType('int<-5, -1>|int<1, 5>', $x);
} else {
assertType('0', $x);
}

if ((float) $b) {
assertType('true', $b);
} else {
assertType('false', $b);
}

if ((float) $s) {
assertType('non-falsy-string', $s);
} else {
assertType("''|'0'", $s);
}
}
Loading