-
Notifications
You must be signed in to change notification settings - Fork 653
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
Weird !falsy assertion paradox when using template conditionals #8412
Comments
I found these snippets: https://psalm.dev/r/46b3483706<?php
/**
* @param array<array{type: string}> $v
* @param "prof"|"organization"|null $onlyType
* @return array<array{type: string}>
*/
function getOwnerObjects(array $v, ?string $onlyType = null): array {
$ok = [];
foreach ($v as $owner) {
if ($onlyType && $onlyType !== $owner['type']) {
continue;
}
$ok []= $owner;
}
return $ok;
}
https://psalm.dev/r/55b41e85e3<?php
/**
* @param array<array{type: string}> $v
* @param "prof"|"organization"|null $onlyType
* @return ($onlyType is null ? array<array{type: string}> : array<array{type: $onlyType}>)
*/
function getOwnerObjects(array $v, ?string $onlyType = null): array {
$ok = [];
foreach ($v as $owner) {
if ($onlyType !== null && $onlyType !== $owner['type']) {
continue;
}
$ok []= $owner;
}
return $ok;
}
|
Those are the same link. |
I found these snippets: https://psalm.dev/r/46b3483706<?php
/**
* @param array<array{type: string}> $v
* @param "prof"|"organization"|null $onlyType
* @return array<array{type: string}>
*/
function getOwnerObjects(array $v, ?string $onlyType = null): array {
$ok = [];
foreach ($v as $owner) {
if ($onlyType && $onlyType !== $owner['type']) {
continue;
}
$ok []= $owner;
}
return $ok;
}
|
Whoops, I meant https://psalm.dev/r/82163ab6b7 :) |
I found these snippets: https://psalm.dev/r/82163ab6b7<?php
/**
* @param array<array{type: string}> $v
* @param "prof"|"organization"|null $onlyType
* @return array<array{type: string}>
*/
function getOwnerObjects(array $v, ?string $onlyType = null): array {
$ok = [];
foreach ($v as $owner) {
if ($onlyType !== null && $onlyType !== $owner['type']) {
continue;
}
$ok []= $owner;
}
return $ok;
}
|
That one also has no issues 😛 |
That's the point, weird how a !falsy is buggy but a !null assertion isn't |
I'm still a bit confused, none of the links you posted have issues. What's different? |
Huh, my bad, I'm apparently blind, must've been an issue on my outdated fork which I didn't notice had disappeared in the psalm.dev REPL :) |
Is this a false-positive maybe? |
I found these snippets: https://psalm.dev/r/c23cbf01bc<?php
/**
* @param array<array{type: string}> $v
* @param "prof"|"organization"|null $onlyType
* @return ($onlyType is null ? array<array{type: string}> : array<array{type: $onlyType}>)
*/
function getOwnerObjects(array $v, ?string $onlyType = null): array {
$ok = [];
foreach ($v as $owner) {
if ($onlyType && $onlyType !== $owner['type']) {
continue;
}
$ok []= $owner;
}
return $ok;
}
|
Whoops, yes it is :) |
https://psalm.dev/r/46b3483706, but the non-templated version works fine: https://psalm.dev/r/46b3483706
Changing the $onlyType assertion to a non-null assertion also fixes it: https://psalm.dev/r/55b41e85e3
The text was updated successfully, but these errors were encountered: