Commit 3dea282 1 parent 7d6c88e commit 3dea282 Copy full SHA for 3dea282
File tree 2 files changed +33
-0
lines changed
src/Psalm/Internal/Type/Comparator
2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -86,6 +86,11 @@ public static function isContainedBy(
86
86
if ($ container_type_part instanceof TNonspecificLiteralString
87
87
&& ($ input_type_part instanceof TLiteralString || $ input_type_part instanceof TNonspecificLiteralString)
88
88
) {
89
+ if ($ container_type_part instanceof TNonEmptyNonspecificLiteralString) {
90
+ return ($ input_type_part instanceof TLiteralString && $ input_type_part ->value !== '' )
91
+ || $ input_type_part instanceof TNonEmptyNonspecificLiteralString;
92
+ }
93
+
89
94
return true ;
90
95
}
91
96
Original file line number Diff line number Diff line change @@ -951,6 +951,34 @@ final class SpecificObject extends stdClass {}
951
951
'ignored_issues ' => [],
952
952
'php_version ' => '8.1 ' ,
953
953
],
954
+ 'nonEmptyLiteralString ' => [
955
+ 'code ' => '<?php
956
+ /**
957
+ * @param literal-string $string
958
+ * @psalm-return ($string is non-empty-literal-string ? string : int)
959
+ */
960
+ function getSomething(string $string)
961
+ {
962
+ if (!$string) {
963
+ return 1;
964
+ }
965
+
966
+ return "";
967
+ }
968
+
969
+ /** @var literal-string $literalString */
970
+ $literalString;
971
+ $something = getSomething($literalString);
972
+ /** @var non-empty-literal-string $nonEmptyliteralString */
973
+ $nonEmptyliteralString;
974
+ $something2 = getSomething($nonEmptyliteralString);
975
+ ' ,
976
+ 'assertions ' => [
977
+ '$something ' => 'int|string ' ,
978
+ '$something2 ' => 'string ' ,
979
+ ],
980
+ 'ignored_issues ' => [],
981
+ ],
954
982
];
955
983
}
956
984
}
You can’t perform that action at this time.
0 commit comments