[php-src] Issue #9516: PHP8.2: (A&B)|D as a param should allow AB or D. Not just A.

From: Date: Fri, 09 Sep 2022 17:42:59 +0000
Subject: [php-src] Issue #9516: PHP8.2: (A&B)|D as a param should allow AB or D. Not just A.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-242392@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/9516 Author: kschatzle ### Description The following code: ```php <?php interface A { } interface B { } interface D { } class A_ implements A {} class B_ implements B {} class AB_ implements A, B {} class D_ implements D {} class T { public function method((A&B)|D $arg): void {} public function method2((B&A)|D $arg): void {} } $t = new T; try { $t->method(new A_); // Bug? echo 'Fail', \PHP_EOL; } catch (\Throwable $throwable) { echo $throwable->getMessage(), \PHP_EOL; } try { $t->method(new B_); echo 'Fail', \PHP_EOL; } catch (\Throwable $throwable) { echo $throwable->getMessage(), \PHP_EOL; } try { $t->method(new AB_); echo 'Pass', \PHP_EOL; } catch (\Throwable $throwable) { echo $throwable->getMessage(), \PHP_EOL; } try { $t->method(new D_); echo 'Pass', \PHP_EOL; } catch (\Throwable $throwable) { echo $throwable->getMessage(), \PHP_EOL; } // Lets try in reverse? try { $t->method2(new A_); echo 'Fail', \PHP_EOL; } catch (\Throwable $throwable) { echo $throwable->getMessage(), \PHP_EOL; } try { $t->method2(new B_); // Bug? echo 'Fail', \PHP_EOL; } catch (\Throwable $throwable) { echo $throwable->getMessage(), \PHP_EOL; } try { $t->method2(new AB_); echo 'Pass', \PHP_EOL; } catch (\Throwable $throwable) { echo $throwable->getMessage(), \PHP_EOL; } try { $t->method2(new D_); echo 'Pass', \PHP_EOL; } catch (\Throwable $throwable) { echo $throwable->getMessage(), \PHP_EOL; } ?> ``` Resulted in this output: ``` Fail T::method(): Argument #1 ($arg) must be of type (A&B)|D, B_ given, called in %s on line %d Pass Pass T::method2(): Argument #1 ($arg) must be of type (B&A)|D, A_ given, called in %s on line %d Fail Pass Pass ``` But I expected this output instead: ``` T::method(): Argument #1 ($arg) must be of type (A&B)|D, A_ given, called in %s on line %d T::method(): Argument #1 ($arg) must be of type (A&B)|D, B_ given, called in %s on line %d Pass Pass T::method2(): Argument #1 ($arg) must be of type (B&A)|D, A_ given, called in %s on line %d T::method2(): Argument #1 ($arg) must be of type (B&A)|D, B_ given, called in %s on line %d Pass Pass ``` ### PHP Version PHP 8.2.0-dev ### Operating System macOS Monterey Version 12.5.1 arm64

« previous php.bugs (#242392) next »