Skip to content

Commit

Permalink
Merge pull request #24 from fmata/never
Browse files Browse the repository at this point in the history
Handle "never" type as non float
  • Loading branch information
Ocramius authored Aug 17, 2022
2 parents ff92658 + 900ae71 commit 0fe4d6b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/FloatTypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PHPStan\Type\FloatType;
use PHPStan\Type\MixedType;
use PHPStan\Type\NeverType;
use PHPStan\Type\Type;

/** @internal class is only for internal tooling use: do not import it in your own projects */
Expand All @@ -17,6 +18,10 @@ public static function isFloat(Type $type): bool
return false;
}

if ($type instanceof NeverType) {
return false;
}

return ! (new FloatType())->isSuperTypeOf($type)->no();
}
}
8 changes: 8 additions & 0 deletions tests/asset/function.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ function doBar(): string
{

}

/**
* @return never
*/
function withNever()
{
throw new \RuntimeException();
}
7 changes: 7 additions & 0 deletions tests/asset/method.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@ public function doBar(): string

}

/**
* @return never
*/
public function withNever()
{
throw new \RuntimeException();
}
}

0 comments on commit 0fe4d6b

Please sign in to comment.