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

No error when adding list to array of non-empty-list #9594

Closed
MoonE opened this issue Apr 2, 2023 · 4 comments
Closed

No error when adding list to array of non-empty-list #9594

MoonE opened this issue Apr 2, 2023 · 4 comments
Labels

Comments

@MoonE
Copy link
Contributor

MoonE commented Apr 2, 2023

There should be a warning when adding a list to an array of non-empty-lists
https://psalm.dev/r/7ddbfc99b9

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/7ddbfc99b9
<?php
class A {
    /**
     * @psalm-var array<int, non-empty-list<string>>
     */
    private array $l = [];

    /** @psalm-param list<string> $v */
    public function addResult(array $v): void {
        $this->l[] = $v;
        /** @psalm-trace $v $this->l */
    }
}
Psalm output (using commit fd4f7b7):

INFO: Trace - 11:0 - $v: list<string>

INFO: Trace - 11:0 - $this->l: non-empty-array<int, non-empty-list<string>>

@orklah orklah added the bug label Apr 2, 2023
@robchett
Copy link
Contributor

Simpler case and proof that type info is lost in both directions

https://psalm.dev/r/e97c284178

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/e97c284178
<?php
/** @var array<int, array<never, never>> $a*/
$a = [[]];
$a[] = ['A'];
// $a should be non-empty-array<int, list<string>>

/** @var array<int, non-empty-list<string>> $b*/
$b = [['A']];
$b[] = [];
// $b should be non-empty-array<int, list<string>>

/** @psalm-trace $a $b */
return [$a, $b];
Psalm output (using commit 5370492):

INFO: Trace - 13:1 - $a: non-empty-array<int, list{'A'}>

INFO: Trace - 13:1 - $b: non-empty-array<int, non-empty-list<string>>

@weirdan
Copy link
Collaborator

weirdan commented Feb 10, 2024

Fixed in #9787 (I assume)

@weirdan weirdan closed this as completed Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants