vimeo / psalm

A static analysis tool for finding errors in PHP applications
https://psalm.dev
MIT License
5.54k stars 660 forks source link

Warn about stubs that duplicate classes/functions from other stubs in internal stubs? #3708

Open TysonAndre opened 4 years ago

TysonAndre commented 4 years ago

For example, if I add the following patch to CoreGenericClasses.phpstub, it doesn't give me any indication that the same class was already declared in src/Psalm/Internal/Stubs/CoreImmutableClasses.phpstub.

Ideally, it would warn, and/or combine any annotations that affect analysis. I haven't checked what would happen if a plugin registered a stub.

Obviously, in this use case, I should be adding the annotation to CoreImmutableClasses instead if I wanted to treat that as potentially unsafe, or use a plugin to modify the method after the stubs get registered.

--- a/src/Psalm/Internal/Stubs/CoreGenericClasses.phpstub
+++ b/src/Psalm/Internal/Stubs/CoreGenericClasses.phpstub
@@ -256,6 +256,19 @@ class Generator implements Traversable {
     public function throw(Throwable $exception) {}
 }

+class Exception implements \Throwable {
+    /**
+     * @psalm-taint-source input
+     * @return string
+     */
+    final public function getTraceAsString() {}
+    /**
+     * @psalm-taint-source input
+     * @return string
+     */
+    public function __toString() {}
+}
+
psalm-github-bot[bot] commented 4 years ago

Hey @TysonAndre, can you reproduce the issue on https://psalm.dev ?