Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object like array with required key not always considered non-empty #5436

Closed
AndrolGenhald opened this issue Mar 19, 2021 · 1 comment
Closed

Comments

@AndrolGenhald
Copy link
Collaborator

https://psalm.dev/r/23869e7fec

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/23869e7fec
<?php

/**
 * @psalm-suppress UnusedParam
 * @param non-empty-array<string, string> $arg
 */
function test(array $arg): void {}

/** @var array{a?: string, b: string} */
$a = ['b' => 'b'];
test($a); // 'b' is required, $a should be non-empty-array

/** @var array{a: string, b?: string} */
$b = ['a' => 'a'];
test($b); // works
Psalm output (using commit 42d3bce):

ERROR: ArgumentTypeCoercion - 11:6 - Argument 1 of test expects non-empty-array<string, string>, parent type array{a?: string, b: string} provided

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant