forked from phan/phan
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix false positive/negative PhanTypeMissingReturn instances
The check was wrong and should have been checking for never returning. Return statements can be omitted if a function unconditionally exits. Closes phan#4537
- Loading branch information
1 parent
0fbd376
commit 7595f3a
Showing
14 changed files
with
70 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
src/043_throws.php:6 PhanPluginNeverReturnFunction Function \throwOutOfBoundsException() never returns and has a return type of void, but phpdoc type never could be used instead | ||
src/043_throws.php:14 PhanPluginNeverReturnMethod Function \ExampleThrow43::throwInvalidArgumentException() never returns and has a return type of (empty union type), but phpdoc type never could be used instead | ||
src/043_throws.php:14 PhanPluginNeverReturnMethod Method \ExampleThrow43::throwInvalidArgumentException() never returns and has a return type of (empty union type), but phpdoc type never could be used instead | ||
src/043_throws.php:20 PhanThrowTypeAbsent \ExampleThrow43::example() can throw throwOutOfBoundsException of type \OutOfBoundsException here, but has no '@throws' declarations for that class | ||
src/043_throws.php:22 PhanThrowTypeAbsentForCall \ExampleThrow43::example() can throw \InvalidArgumentException because it calls \ExampleThrow43::throwInvalidArgumentException(), but has no '@throws' declarations for that class | ||
src/043_throws.php:30 PhanThrowTypeAbsentForCall \ExampleThrow43::example2() can throw \InvalidArgumentException because it calls \ExampleThrow43::throwInvalidArgumentException(), but has no '@throws' declarations for that class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
src/123_throw_static.php:2 PhanUnreferencedClass Possibly zero references to class \ThrowingException688 | ||
src/123_throw_static.php:6 PhanPluginNeverReturnMethod Function \ThrowingException688::throw() never returns and has a return type of (empty union type), but phpdoc type never could be used instead | ||
src/123_throw_static.php:6 PhanPluginNeverReturnMethod Method \ThrowingException688::throw() never returns and has a return type of (empty union type), but phpdoc type never could be used instead | ||
src/123_throw_static.php:6 PhanUnreferencedPublicMethod Possibly zero references to public method \ThrowingException688::throw() | ||
src/123_throw_static.php:13 PhanPluginNeverReturnMethod Function \ThrowingException688::throwOther() never returns and has a return type of (empty union type), but phpdoc type never could be used instead | ||
src/123_throw_static.php:13 PhanPluginNeverReturnMethod Method \ThrowingException688::throwOther() never returns and has a return type of (empty union type), but phpdoc type never could be used instead | ||
src/123_throw_static.php:13 PhanUnreferencedPublicMethod Possibly zero references to public method \ThrowingException688::throwOther() | ||
src/123_throw_static.php:14 PhanThrowTypeMismatch \ThrowingException688::throwOther() throws new RuntimeException('unexpected') of type \RuntimeException here, but it only has declarations of '@throws static' | ||
src/123_throw_static.php:20 PhanPluginNeverReturnMethod Function \ThrowingException688::throwStatic() never returns and has a return type of (empty union type), but phpdoc type never could be used instead | ||
src/123_throw_static.php:20 PhanPluginNeverReturnMethod Method \ThrowingException688::throwStatic() never returns and has a return type of (empty union type), but phpdoc type never could be used instead | ||
src/123_throw_static.php:20 PhanUnreferencedPublicMethod Possibly zero references to public method \ThrowingException688::throwStatic() | ||
src/123_throw_static.php:21 PhanThrowTypeMismatch \ThrowingException688::throwStatic() throws new static('unexpected') of type static here, but it only has declarations of '@throws \RuntimeException' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
src/133_throw_in_to_string.php:6 PhanPluginNeverReturnMethod Function \X133::__toString() never returns and has a return type of (empty union type), but phpdoc type never could be used instead | ||
src/133_throw_in_to_string.php:6 PhanPluginNeverReturnMethod Method \X133::__toString() never returns and has a return type of (empty union type), but phpdoc type never could be used instead | ||
src/133_throw_in_to_string.php:6 PhanThrowCommentInToString \X133::__toString() documents that it throws \RuntimeException, but throwing in __toString() is a fatal error prior to PHP 7.4 | ||
src/133_throw_in_to_string.php:7 PhanThrowStatementInToString \X133::__toString() throws \RuntimeException here, but throwing in __toString() is a fatal error prior to PHP 7.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
src/202_never_return.php:7 PhanUnusedProtectedMethodParameter Parameter $x is never used |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
class BaseClass { | ||
/** | ||
* @return never | ||
*/ | ||
protected function fatalError( $x ) { | ||
exit(); | ||
} | ||
} | ||
|
||
class ChildClass extends BaseClass { | ||
/** | ||
* @return never | ||
*/ | ||
public function fatalError( $x ) { | ||
echo implode(['a' => $x]); | ||
parent::fatalError( $x ); | ||
} | ||
|
||
public function main() { | ||
$this->fatalError( 42 ); | ||
} | ||
} | ||
var_dump((new ChildClass())->main()); |