php-standard-library / phpstan-extension

14 stars 4 forks source link

Nullable non-empty-string is coerced as nullable string #9

Open EmilMassey opened 2 years ago

EmilMassey commented 2 years ago

I'm unable to use shape with nullable non-empty-string (as well as union(null(), non_empty_string()). I'm not sure if the issue is in the extension or in the phpstan itself.

/** @param array{foo: non-empty-string, bar: non-empty-string|null} $arr */
function test(array $arr) {}

$arr = shape([
  'foo' => non_empty_string(),
  'bar' => nullable(non_empty_string()),
])->coerce($input);

test($arr);

Expects: array{foo: non-empty-string, bar: non-empty-string|null}, array{foo: non-empty-string, bar: string|null}. given