From 2ec77fe29c212b44ddf3ca6fcb709f81551837c8 Mon Sep 17 00:00:00 2001 From: Ricardo Boss Date: Mon, 6 Dec 2021 00:33:57 +0100 Subject: [PATCH] Make name property of enum cases return non-empty-strings (vimeo/psalm#6964) --- .../Expression/Fetch/AtomicPropertyFetchAnalyzer.php | 2 +- tests/EnumTest.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php index a3547a51d..9927c6fa2 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php @@ -202,7 +202,7 @@ class AtomicPropertyFetchAnalyzer new Type\Union([new Type\Atomic\TLiteralString($lhs_type_part->case_name)]) ); } else { - $statements_analyzer->node_data->setType($stmt, Type::getString()); + $statements_analyzer->node_data->setType($stmt, Type::getNonEmptyString()); } } else { self::handleNonExistentProperty( diff --git a/tests/EnumTest.php b/tests/EnumTest.php index 7eb56dfe4..7056f7a98 100644 --- a/tests/EnumTest.php +++ b/tests/EnumTest.php @@ -126,6 +126,9 @@ class EnumTest extends TestCase case PUBLISHED; case ARCHIVED; + /** + * @return non-empty-string + */ public function get(): string { return $this->name;