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

PHPStan not follow DNF Type Declaration Constraints (PHP 8.2+) #10913

Open
LastDragon-ru opened this issue Apr 20, 2024 · 0 comments
Open

PHPStan not follow DNF Type Declaration Constraints (PHP 8.2+) #10913

LastDragon-ru opened this issue Apr 20, 2024 · 0 comments

Comments

@LastDragon-ru
Copy link

LastDragon-ru commented Apr 20, 2024

Bug report

The code is good for phpstan, but it is not valid for PHP :) (see https://wiki.php.net/rfc/dnf_types and https://php.watch/versions/8.2/dnf-types)

<?php declare(strict_types = 1);

interface X {}
interface Y {}

// Fatal error: Type Y&X is redundant with type X&Y in
// https://3v4l.org/gpAXA
function a(): (X&Y)|(Y&X) {
    return new class() implements X, Y {};
}

// Fatal error: Type X&Y is redundant as it is more restrictive than type X 
// https://3v4l.org/0jneS
function b(): (X&Y)|X {
    return new class() implements X {};
}

Code snippet that reproduces the problem

https://phpstan.org/r/75ab1049-8ffd-41bb-93ad-3082124ff2ec

Expected output

  • Fatal error: Type Y&X is redundant with type X&Y in
  • Fatal error: Type X&Y is redundant as it is more restrictive than type X

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

Yep, helps a lot to move types intersections from phpdoc to code.

@LastDragon-ru LastDragon-ru changed the title PHPStan not follow DNF Type Declaration Constraints (PHP 8.2) PHPStan not follow DNF Type Declaration Constraints (PHP 8.2+) Apr 20, 2024
@ondrejmirtes ondrejmirtes added this to the Static reflection milestone Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants