From 9db43cdaaef5ec1b6cce5886f4fffd7bb993bce4 Mon Sep 17 00:00:00 2001 From: orklah Date: Tue, 23 Nov 2021 19:54:09 +0100 Subject: [PATCH 1/2] don't accept unresolved literal string as valid callable-strings --- src/Psalm/Internal/Type/Comparator/ScalarTypeComparator.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Psalm/Internal/Type/Comparator/ScalarTypeComparator.php b/src/Psalm/Internal/Type/Comparator/ScalarTypeComparator.php index 9df93389bbc..8026c1c29aa 100644 --- a/src/Psalm/Internal/Type/Comparator/ScalarTypeComparator.php +++ b/src/Psalm/Internal/Type/Comparator/ScalarTypeComparator.php @@ -582,6 +582,11 @@ public static function isContainedBy( } } + if (!$input_callable) { + //we could not find a callable for the input type, so the input is not contained in the container + return false; + } + return true; } From 7c6b86cef3fab3408d67a4bd636a44e4e7234117 Mon Sep 17 00:00:00 2001 From: orklah Date: Tue, 23 Nov 2021 20:04:52 +0100 Subject: [PATCH 2/2] suppress error and add test --- tests/CallableTest.php | 12 ++++++++++++ tests/TypeParseTest.php | 1 + 2 files changed, 13 insertions(+) diff --git a/tests/CallableTest.php b/tests/CallableTest.php index ee67e83e27c..77895a82ad3 100644 --- a/tests/CallableTest.php +++ b/tests/CallableTest.php @@ -1219,6 +1219,18 @@ function foo(string $c) : void { }', 'error_message' => 'InvalidScalarArgument', ], + 'inexistantCallableinCallableString' => [ + ' 'InvalidArgument', + ], ]; } } diff --git a/tests/TypeParseTest.php b/tests/TypeParseTest.php index 373dae9f135..be82866429a 100644 --- a/tests/TypeParseTest.php +++ b/tests/TypeParseTest.php @@ -973,6 +973,7 @@ function someFunction(string $param, array $param2, ?int $param3 = null) : strin } } + /** @psalm-suppress InvalidArgument Psalm couldn't detect the function exists */ $reflectionFunc = new \ReflectionFunction('Psalm\Tests\someFunction'); $reflectionParams = $reflectionFunc->getParameters();