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

Null coalesce operator can be used for type specifying shorthand #7501

Closed
zonuexe opened this issue Jun 20, 2022 · 2 comments · Fixed by phpstan/phpstan-src#1707
Closed

Null coalesce operator can be used for type specifying shorthand #7501

zonuexe opened this issue Jun 20, 2022 · 2 comments · Fixed by phpstan/phpstan-src#1707

Comments

@zonuexe
Copy link
Contributor

zonuexe commented Jun 20, 2022

Feature request

The following two types of expressions are equivalent, but they don't work as expected with the null coalesce operator.

/**
 * @param array{key?: mixed} $a
 */
function f(array $a): void
{
	if (isset($a['key']) && is_int($a['key'])) {
		assertType('array{key: int}', $a);
	}

	if (is_int($a['key'] ?? null)) {
		assertType('array{key: int}', $a);
	}
}

https://phpstan.org/r/3bee56cc-e003-43e2-b4ad-f75e81c6652e

I found out that this commit doesn't handle this pattern. phpstan/phpstan-src@b98a1cf

Did PHPStan help you today? Did it make you happy in any way?

This morning, it became a hot topic in Japan that the Japanese government's youth development program for IT innovation decided to support a new programming language project with the "Union Grand Unified Theory". https://www.ipa.go.jp/jinzai/mitou/2022/gaiyou_tk-1.html

Although details have not been clarified yet, the concept of the Cotton language seems to a statically typed language based on the union type instead of the sum type. We rely heavily on union types in PHP, so I'm looking forward to the results of this project.

@rajyan
Copy link
Contributor

rajyan commented Jun 21, 2022

These are duplicates
#7244
#5304
I'm looking forward to fixing it!

@github-actions
Copy link

github-actions bot commented Oct 8, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants