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

Some strange NEVER compatibility issue #4006

Closed
b1rdex opened this issue Oct 26, 2020 · 7 comments
Closed

Some strange NEVER compatibility issue #4006

b1rdex opened this issue Oct 26, 2020 · 7 comments
Labels
Milestone

Comments

@b1rdex
Copy link
Contributor

b1rdex commented Oct 26, 2020

https://phpstan.org/r/cbdc5e54-29b0-486f-9f5b-cac0e4366768

<?php declare(strict_types = 1);

interface foo {
	/**
	 * @return void
	 * @phpstan-return never
	 */
	public function bar();	
}

class bar implements foo {
	public function bar(): void {
		throw new \Exception();	
	}
}

Removing the native void return type fixes the issue.

@ondrejmirtes
Copy link
Member

Hi, I fixed the error message: phpstan/phpstan-src@38fe693

Otherwise the reported error seems legit.

@b1rdex
Copy link
Contributor Author

b1rdex commented Oct 27, 2020

Hmm, I don't get why it's legit. I thought that PHPDoc types are inherited and it's a bug. Why it isn't possible to declare a native return type besides never? The only option here is to declare a native type on the interface?

@b1rdex
Copy link
Contributor Author

b1rdex commented Oct 27, 2020

https://phpstan.org/r/0e134edb-d7fe-4d69-a459-c9ae46423018
Why the error is still present when I add never using PHPDoc?

@ondrejmirtes
Copy link
Member

You're hitting the edges of the type system where things are weird :) Usually you'd get this message:

PHPDoc tag @return with type NEVER is incompatible with native type void.

But because it's *NEVER* that's a subtype of every type, this message doesn't show up, but the PHPDoc gets not used anyway, so it's still void in bar vs. never in foo.

For void it's technically valid to have return; in the method body, but for never it's not, so these types aren't exactly interchangeable.

@ondrejmirtes
Copy link
Member

I could probably make never + void result in never...

@ondrejmirtes ondrejmirtes reopened this Oct 27, 2020
@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Oct 27, 2020
@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@1857c6c

@github-actions
Copy link

github-actions bot commented May 9, 2021

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 May 9, 2021
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

2 participants