From e7b8983b7ea811ae95131134e0c4c40d6777e856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Mon, 20 Apr 2020 23:17:47 +0200 Subject: [PATCH] Make Throwable methods overridable (#3203) Methods from \Exception cannot be overriden, but that does not mean methods from \Throwable cannot be. Closes #3202 --- .../Stubs/CoreImmutableClasses.phpstub | 14 +++++++------- tests/MethodSignatureTest.php | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/Psalm/Internal/Stubs/CoreImmutableClasses.phpstub b/src/Psalm/Internal/Stubs/CoreImmutableClasses.phpstub index 2557e5791..94f3029e6 100644 --- a/src/Psalm/Internal/Stubs/CoreImmutableClasses.phpstub +++ b/src/Psalm/Internal/Stubs/CoreImmutableClasses.phpstub @@ -21,39 +21,39 @@ interface Throwable /** * @psalm-mutation-free */ - public final function getMessage() : string; + public function getMessage() : string; /** * @psalm-mutation-free * * @return int|string https://www.php.net/manual/en/throwable.getcode.php */ - public final function getCode(); + public function getCode(); /** * @psalm-mutation-free */ - public final function getFile() : string; + public function getFile() : string; /** * @psalm-mutation-free */ - public final function getLine() : int; + public function getLine() : int; /** * @psalm-mutation-free */ - public final function getTrace() : array; + public function getTrace() : array; /** * @psalm-mutation-free */ - public final function getPrevious() : ?Throwable; + public function getPrevious() : ?Throwable; /** * @psalm-mutation-free */ - public final function getTraceAsString() : string; + public function getTraceAsString() : string; } class Exception implements Throwable diff --git a/tests/MethodSignatureTest.php b/tests/MethodSignatureTest.php index 623ef671a..dcc8296cd 100644 --- a/tests/MethodSignatureTest.php +++ b/tests/MethodSignatureTest.php @@ -773,6 +773,25 @@ class MethodSignatureTest extends TestCase [], '7.4' ], + 'allowOverridingThrowable' => [ + '