1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Revert "Correct Psalm’s concept of string emptiness"

This reverts commit 331ce8ead4f4b55a62b535ac93afc9686b8d0043.

It was too hasty
This commit is contained in:
Matt Brown 2021-02-03 01:09:58 -05:00
parent 331ce8ead4
commit 03665b9646
7 changed files with 16 additions and 49 deletions

View File

@ -31,7 +31,7 @@ use function array_values;
use const PATHINFO_EXTENSION;
/**
* @psalm-type TaggedCodeType = array<int, array{0: int, 1: string}>
* @psalm-type TaggedCodeType = array<int, array{0: int, 1: non-empty-string}>
*
* @psalm-type FileMapType = array{
* 0: TaggedCodeType,
@ -153,12 +153,12 @@ class Analyzer
private $existing_issues = [];
/**
* @var array<string, array<int, array{0: int, 1: string}>>
* @var array<string, array<int, array{0: int, 1: non-empty-string}>>
*/
private $reference_map = [];
/**
* @var array<string, array<int, array{0: int, 1: string}>>
* @var array<string, array<int, array{0: int, 1: non-empty-string}>>
*/
private $type_map = [];
@ -1161,7 +1161,7 @@ class Analyzer
string $reference,
int $argument_number
): void {
if (!$reference) {
if ($reference === '') {
throw new \UnexpectedValueException('non-empty reference expected');
}

View File

@ -216,7 +216,7 @@ class Functions
if ($function_name[0] === '\\') {
$function_name = substr($function_name, 1);
if (!$function_name) {
if ($function_name === '') {
throw new \UnexpectedValueException('Malformed function name');
}

View File

@ -260,8 +260,7 @@ class ScalarTypeComparator
if ($container_type_part instanceof TNonEmptyString
&& $input_type_part instanceof TLiteralString
&& ($input_type_part->value === ''
|| $input_type_part->value === '0')
&& $input_type_part->value === ''
) {
return false;
}

View File

@ -362,6 +362,8 @@ class NegatedAssertionReconciler extends Reconciler
$did_remove_type = true;
}
} elseif ($assertion === 'string()') {
$existing_var_type->addType(new Type\Atomic\TNonEmptyString());
}
} elseif ($scalar_type === 'string') {
$scalar_value = substr($assertion, $bracket_pos + 1, -1);

View File

@ -47,8 +47,8 @@ class FakeFileReferenceCacheProvider extends \Psalm\Internal\Provider\FileRefere
* @var array<
* string,
* array{
* 0: array<int, array{0: int, 1: string}>,
* 1: array<int, array{0: int, 1: string}>,
* 0: array<int, array{0: int, 1: non-empty-string}>,
* 1: array<int, array{0: int, 1: non-empty-string}>,
* 2: array<int, array{0: int, 1: non-empty-string, 2: int}>
* }
* >
@ -190,8 +190,8 @@ class FakeFileReferenceCacheProvider extends \Psalm\Internal\Provider\FileRefere
* @return array<
* string,
* array{
* 0: array<int, array{0: int, 1: string}>,
* 1: array<int, array{0: int, 1: string}>,
* 0: array<int, array{0: int, 1: non-empty-string}>,
* 1: array<int, array{0: int, 1: non-empty-string}>,
* 2: array<int, array{0: int, 1: non-empty-string, 2: int}>
* }
* >
@ -205,8 +205,8 @@ class FakeFileReferenceCacheProvider extends \Psalm\Internal\Provider\FileRefere
* @param array<
* string,
* array{
* 0: array<int, array{0: int, 1: string}>,
* 1: array<int, array{0: int, 1: string}>,
* 0: array<int, array{0: int, 1: non-empty-string}>,
* 1: array<int, array{0: int, 1: non-empty-string}>,
* 2: array<int, array{0: int, 1: non-empty-string, 2: int}>
* }
* > $file_maps

View File

@ -2411,7 +2411,7 @@ class ConditionalTest extends \Psalm\Tests\TestCase
return [$type];
}'
],
'SKIPPED-nonEmptyStringAfterLiteralCheck' => [
'nonEmptyStringAfterLiteralCheck' => [
'<?php
/**
* @param non-empty-string $greeting
@ -2423,7 +2423,7 @@ class ConditionalTest extends \Psalm\Tests\TestCase
/** @var string */
$hello = "foo";
if ($hello === "" || $hello === "0") {
if ($hello === "") {
throw new \Exception("an empty string is not a greeting");
}

View File

@ -1053,40 +1053,6 @@ class ValueTest extends \Psalm\Tests\TestCase
}',
'error_message' => 'ArgumentTypeCoercion'
],
'zeroIsEmptyString' => [
'<?php
/**
* @param non-empty-string $s
*/
function foo(string $s) : void {}
foo("0");',
'error_message' => 'InvalidArgument'
],
'notLiteralEmptyIsNotNotEmptyString' => [
'<?php
/**
* @param non-empty-string $s
*/
function foo(string $s) : void {}
function takesString(string $s) : void {
if ($s !== "") {
foo($s);
}
}',
'error_message' => 'ArgumentTypeCoercion'
],
'nonEmptyStringCannotBeStringZero' => [
'<?php
/**
* @param non-empty-string $s
*/
function foo(string $s) : void {
if ($s === "0") {}
}',
'error_message' => 'TypeDoesNotContainType'
],
];
}
}