forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve error messages related to void/never return types of methods
- Loading branch information
1 parent
b5a23d8
commit d84ed03
Showing
10 changed files
with
68 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--TEST-- | ||
never return type: unacceptable cases: empty return in a method | ||
--FILE-- | ||
<?php | ||
|
||
class Foo { | ||
public function bar(): never { | ||
return; | ||
} | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: A never-returning method must not return in %s on line %d |
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,21 @@ | ||
--TEST-- | ||
never return type: unacceptable cases: implicit return in a method | ||
--FILE-- | ||
<?php | ||
|
||
class Foo { | ||
public static function bar(): never { | ||
if (false) { | ||
throw new Exception('bad'); | ||
} | ||
} | ||
} | ||
|
||
try { | ||
Foo::bar(); | ||
} catch (TypeError $e) { | ||
echo $e->getMessage() . "\n"; | ||
} | ||
?> | ||
--EXPECT-- | ||
Foo::bar(): never-returning method must not implicitly return |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--TEST-- | ||
void return type: unacceptable cases: explicit null return in a method | ||
--FILE-- | ||
<?php | ||
|
||
class Foo { | ||
public function bar(): void { | ||
return -1; // not permitted in a void function | ||
} | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: A void method must not return a value in %s on line %d |
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