Skip to content

Commit

Permalink
should be non-falsy-string instead of non-empty-string in most cases
Browse files Browse the repository at this point in the history
  • Loading branch information
kkmuffme committed Jan 13, 2024
1 parent a2bf5cb commit 4092618
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Psalm/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public static function getString(?string $value = null): Union
return new Union([$value === null ? new TString() : self::getAtomicStringFromLiteral($value)]);
}

/** @return TLiteralString|TNonEmptyString */
/** @return TLiteralString|TNonEmptyString|TNonFalsyString */
public static function getAtomicStringFromLiteral(string $value, bool $from_docblock = false): TString
{
$config = Config::getInstance();
Expand All @@ -289,8 +289,10 @@ public static function getAtomicStringFromLiteral(string $value, bool $from_docb
if (!$type) {
if ($value === '' || strlen($value) < $config->max_string_length) {
$type = new TLiteralString($value, $from_docblock);
} else {
} elseif ($value === '0') {
$type = new TNonEmptyString($from_docblock);
} else {
$type = new TNonFalsyString($from_docblock);
}
}

Expand Down
7 changes: 7 additions & 0 deletions tests/TypeCombinationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ function takesLiteralString($arg) {}
takesLiteralString($c);
}',
],
'tooLongLiteralShouldBeNonFalsyString' => [
'code' => '<?php
$x = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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