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

Return type T does not accept T&null #5860

Closed
jlherren opened this issue Nov 1, 2021 · 5 comments
Closed

Return type T does not accept T&null #5860

jlherren opened this issue Nov 1, 2021 · 5 comments
Labels
Milestone

Comments

@jlherren
Copy link

jlherren commented Nov 1, 2021

Bug report

After upgrading to PHPStan 1.0, I find that a function that should return T does not accept returning T&null, where T is a template type.

Code snippet that reproduces the problem

/**
 * @template T
 * @param T $t
 * @return T
 */
function test($t) {
	if ($t === null) {
		return $t; // <-- Error: Function test() should return T but returns T&null.
	}
	return $t;
}

https://phpstan.org/r/984459d4-1124-4ca9-888c-dc3d31b979fb

Expected output

No error

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

I'm all excited about the 1.0 release :)

@voku
Copy link
Contributor

voku commented Nov 1, 2021

Looks like a doublicate issue, or?: #5591

@ondrejmirtes ondrejmirtes added this to the Generics milestone Jan 31, 2022
@ondrejmirtes
Copy link
Member

/cc @arnaud-lb Also this one :)

@phpstan-bot
Copy link
Contributor

@jlherren After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-9: Function test() should return T but returns T&null.
+No errors

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@9f12f0f

@github-actions
Copy link

github-actions bot commented Mar 6, 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 Mar 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants