From b49b5f1c200d7c66931e24abf636cba99808bbdb Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Thu, 10 Feb 2022 18:46:22 -0500 Subject: [PATCH] Make error message for truthy/falsy more accurate --- .../Analyzer/Statements/Block/IfConditionalAnalyzer.php | 8 ++++---- tests/JsonOutputTest.php | 2 +- tests/TypeReconciliation/InArrayTest.php | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfConditionalAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfConditionalAnalyzer.php index bf03622e229..8601b0c261e 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfConditionalAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfConditionalAnalyzer.php @@ -333,7 +333,7 @@ public static function handleParadoxicalCondition( if ($type->from_docblock) { IssueBuffer::maybeAdd( new DocblockTypeContradiction( - 'Operand of type ' . $type->getId() . ' is always false', + 'Operand of type ' . $type->getId() . ' is always falsy', new CodeLocation($statements_analyzer, $stmt), $type->getId() . ' falsy' ), @@ -342,7 +342,7 @@ public static function handleParadoxicalCondition( } else { IssueBuffer::maybeAdd( new TypeDoesNotContainType( - 'Operand of type ' . $type->getId() . ' is always false', + 'Operand of type ' . $type->getId() . ' is always falsy', new CodeLocation($statements_analyzer, $stmt), $type->getId() . ' falsy' ), @@ -355,7 +355,7 @@ public static function handleParadoxicalCondition( if ($type->from_docblock) { IssueBuffer::maybeAdd( new RedundantConditionGivenDocblockType( - 'Operand of type ' . $type->getId() . ' is always true', + 'Operand of type ' . $type->getId() . ' is always truthy', new CodeLocation($statements_analyzer, $stmt), $type->getId() . ' falsy' ), @@ -364,7 +364,7 @@ public static function handleParadoxicalCondition( } else { IssueBuffer::maybeAdd( new RedundantCondition( - 'Operand of type ' . $type->getId() . ' is always true', + 'Operand of type ' . $type->getId() . ' is always truthy', new CodeLocation($statements_analyzer, $stmt), $type->getId() . ' falsy' ), diff --git a/tests/JsonOutputTest.php b/tests/JsonOutputTest.php index f497091502f..d2f10959346 100644 --- a/tests/JsonOutputTest.php +++ b/tests/JsonOutputTest.php @@ -144,7 +144,7 @@ function fooFoo(?string $a, ?string $b): void { } }', 'error_count' => 1, - 'message' => 'Operand of type non-falsy-string is always true', + 'message' => 'Operand of type non-falsy-string is always truthy', 'line' => 4, 'error' => '$b', ], diff --git a/tests/TypeReconciliation/InArrayTest.php b/tests/TypeReconciliation/InArrayTest.php index 905b7f4c1ef..4e3427c8731 100644 --- a/tests/TypeReconciliation/InArrayTest.php +++ b/tests/TypeReconciliation/InArrayTest.php @@ -313,7 +313,7 @@ function assertInArray($x, $y) { return $x; }', - 'error_message' => 'DocblockTypeContradiction - src' . DIRECTORY_SEPARATOR . 'somefile.php:8:29 - Operand of type false is always false', + 'error_message' => 'DocblockTypeContradiction - src' . DIRECTORY_SEPARATOR . 'somefile.php:8:29 - Operand of type false is always falsy', ], 'assertNegatedInArrayOfNotIntersectingTypeTriggersRedundantCondition' => [ 'code' => ' 'RedundantConditionGivenDocblockType - src' . DIRECTORY_SEPARATOR . 'somefile.php:8:29 - Operand of type true is always true', + 'error_message' => 'RedundantConditionGivenDocblockType - src' . DIRECTORY_SEPARATOR . 'somefile.php:8:29 - Operand of type true is always truthy', ], 'assertInArrayOfNotIntersectingTypeTriggersDocblockTypeContradiction' => [ 'code' => ' 'DocblockTypeContradiction - src' . DIRECTORY_SEPARATOR . 'somefile.php:8:29 - Operand of type false is always false', + 'error_message' => 'DocblockTypeContradiction - src' . DIRECTORY_SEPARATOR . 'somefile.php:8:29 - Operand of type false is always falsy', ], 'assertInArrayOfNotIntersectingTypeReturnsTriggersDocblockTypeContradiction' => [ 'code' => ' 'DocblockTypeContradiction - src' . DIRECTORY_SEPARATOR . 'somefile.php:8:29 - Operand of type false is always false', + 'error_message' => 'DocblockTypeContradiction - src' . DIRECTORY_SEPARATOR . 'somefile.php:8:29 - Operand of type false is always falsy', 'ignored_issues' => ['RedundantConditionGivenDocblockType'], ], 'inArrayDetectType' => [