1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Make Throwable methods overridable (#3203)

Methods from \Exception cannot be overriden, but that does not mean
methods from \Throwable cannot be.

Closes #3202
This commit is contained in:
Grégoire Paris 2020-04-20 23:17:47 +02:00 committed by GitHub
parent 6b42efed3f
commit e7b8983b7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 7 deletions

View File

@ -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

View File

@ -773,6 +773,25 @@ class MethodSignatureTest extends TestCase
[],
'7.4'
],
'allowOverridingThrowable' => [
'<?php
/**
* @psalm-immutable
*/
interface MyException extends \Throwable
{
/**
* Informative comment
*/
public function getMessage(): string;
public function getCode();
public function getFile(): string;
public function getLine(): int;
public function getTrace(): array;
public function getPrevious(): ?\Throwable;
public function getTraceAsString(): string;
}'
]
];
}