Skip to content

Commit

Permalink
Prevent false-positive for Exception::__toString overriding
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jul 2, 2020
1 parent 0c582e9 commit cb94764
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Psalm/Internal/Stubs/CoreImmutableClasses.phpstub
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ interface Throwable
public function getTraceAsString() : string;

/**
* @return string
* @psalm-taint-source input
*/
public function __toString() : string;
public function __toString();
}

/**
Expand Down Expand Up @@ -137,9 +138,10 @@ class Exception implements Throwable
public final function getTraceAsString() : string {}

/**
* @return string
* @psalm-taint-source input
*/
public function __toString() : string {}
public function __toString() {}
}

/**
Expand Down Expand Up @@ -212,7 +214,8 @@ class Error implements Throwable
public final function getTraceAsString() : string {}

/**
* @return string
* @psalm-taint-source input
*/
public function __toString() : string {}
public function __toString() {}
}
19 changes: 19 additions & 0 deletions tests/MethodSignatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,25 @@ public function getTrace(): array;
public function getPrevious(): ?\Throwable;
public function getTraceAsString(): string;
}'
],
'allowExecptionToStringWithNoType' => [
'<?php
class E extends Exception {
public function __toString() {
return "hello";
}
}'
],
'allowExecptionToStringIn71' => [
'<?php
class E extends Exception {
public function __toString() : string {
return "hello";
}
}',
[],
[],
'7.1'
]
];
}
Expand Down

0 comments on commit cb94764

Please sign in to comment.