From d35313182f07313b6f6ba516650354ae22429b91 Mon Sep 17 00:00:00 2001 From: VincentLanglet <9052536+VincentLanglet@users.noreply.github.com> Date: Sun, 14 Jun 2026 17:51:10 +0000 Subject: [PATCH] RequiredPhpVersionVisitor: report native union types as requiring PHP 8.0 - Emit a PHP 8.0 requirement for every `Node\UnionType` (native union type declarations such as `A|B` are a parse error on PHP 7.4 and lower). - The existing inner-type checks (DNF intersections -> 8.2, standalone `true` -> 8.2) still take precedence via the highest-version-wins `require()` logic. - Intersection types were already covered (`Node\IntersectionType` -> 8.1), so no change was needed there; the visitor's other type-syntax families (standalone null/false/true, mixed) are likewise unchanged. - Add `union type`, `union return type` and `nullable union type` cases to RequiredPhpVersionCommentTest::dataDetectedVersion. - Add `// lint >= 8.0` comments to the fixtures that newly trip the detector because they use native union types without advertising a minimum version. For nsrt fixtures that carried `declare(strict_types = 1)` on line 1, the comment is placed immediately after `require(self::PHP_8_0, 'union types', $node); foreach ($node->types as $innerType) { if ($innerType instanceof Node\IntersectionType) { $this->require(self::PHP_8_2, 'disjunctive normal form types', $innerType); diff --git a/tests/PHPStan/Analyser/data/bug-9860.php b/tests/PHPStan/Analyser/data/bug-9860.php index d3702fed7ac..1853527ed68 100644 --- a/tests/PHPStan/Analyser/data/bug-9860.php +++ b/tests/PHPStan/Analyser/data/bug-9860.php @@ -1,4 +1,4 @@ -= 8.0 namespace Bug9860; diff --git a/tests/PHPStan/Analyser/nsrt/bug-11703.php b/tests/PHPStan/Analyser/nsrt/bug-11703.php index ae1a91127b2..ec2f07fbcfb 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-11703.php +++ b/tests/PHPStan/Analyser/nsrt/bug-11703.php @@ -1,5 +1,5 @@ -= 8.0 +declare(strict_types = 1); namespace Bug11703; use function PHPStan\Testing\assertType; diff --git a/tests/PHPStan/Analyser/nsrt/bug-12125.php b/tests/PHPStan/Analyser/nsrt/bug-12125.php index 815e3cb7017..c7dc37ad9c7 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-12125.php +++ b/tests/PHPStan/Analyser/nsrt/bug-12125.php @@ -1,5 +1,5 @@ -= 8.0 +declare(strict_types = 1); namespace Bug12125; use ArrayAccess; diff --git a/tests/PHPStan/Analyser/nsrt/bug-13358.php b/tests/PHPStan/Analyser/nsrt/bug-13358.php index 43cdeeca2f4..6482ddca2d7 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-13358.php +++ b/tests/PHPStan/Analyser/nsrt/bug-13358.php @@ -1,5 +1,5 @@ -= 8.0 +declare(strict_types = 1); namespace Bug13358; use function PHPStan\Testing\assertType; diff --git a/tests/PHPStan/Analyser/nsrt/bug-14319.php b/tests/PHPStan/Analyser/nsrt/bug-14319.php index cbf89d13dcf..c253aa5cdc2 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-14319.php +++ b/tests/PHPStan/Analyser/nsrt/bug-14319.php @@ -1,4 +1,4 @@ -= 8.0 namespace Bug14319; diff --git a/tests/PHPStan/Analyser/nsrt/bug-14710.php b/tests/PHPStan/Analyser/nsrt/bug-14710.php index 6d208e77ca2..711580f5365 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-14710.php +++ b/tests/PHPStan/Analyser/nsrt/bug-14710.php @@ -1,5 +1,5 @@ -= 8.0 +declare(strict_types = 1); namespace Bug14710; use function PHPStan\Testing\assertType; diff --git a/tests/PHPStan/Analyser/nsrt/bug-7259.php b/tests/PHPStan/Analyser/nsrt/bug-7259.php index df6eb0aaf47..571e61f009d 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-7259.php +++ b/tests/PHPStan/Analyser/nsrt/bug-7259.php @@ -1,5 +1,5 @@ -= 8.0 +declare(strict_types = 1); namespace Bug7259; use function PHPStan\Testing\assertType; diff --git a/tests/PHPStan/Analyser/nsrt/bug-7987.php b/tests/PHPStan/Analyser/nsrt/bug-7987.php index 23bda9fb31f..ed7a2a86094 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-7987.php +++ b/tests/PHPStan/Analyser/nsrt/bug-7987.php @@ -1,5 +1,5 @@ -= 8.0 +declare(strict_types=1); namespace Bug7987; use function PHPStan\Testing\assertType; diff --git a/tests/PHPStan/Analyser/nsrt/bug-9208.php b/tests/PHPStan/Analyser/nsrt/bug-9208.php index fa9ec21a301..923c7e7ba4c 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-9208.php +++ b/tests/PHPStan/Analyser/nsrt/bug-9208.php @@ -1,4 +1,4 @@ -= 8.0 namespace Bug9208; diff --git a/tests/PHPStan/Analyser/nsrt/bug-9360.php b/tests/PHPStan/Analyser/nsrt/bug-9360.php index 668affdb43d..1c1b667fab0 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-9360.php +++ b/tests/PHPStan/Analyser/nsrt/bug-9360.php @@ -1,5 +1,5 @@ -= 8.0 +declare(strict_types = 1); namespace Bug9360; use function PHPStan\Testing\assertType; diff --git a/tests/PHPStan/Analyser/nsrt/bug-9404.php b/tests/PHPStan/Analyser/nsrt/bug-9404.php index e03c4cd3861..232648aa8fb 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-9404.php +++ b/tests/PHPStan/Analyser/nsrt/bug-9404.php @@ -1,4 +1,4 @@ -= 8.0 namespace Bug9404; diff --git a/tests/PHPStan/Analyser/nsrt/date-format.php b/tests/PHPStan/Analyser/nsrt/date-format.php index 2f11a334717..e01319f2804 100644 --- a/tests/PHPStan/Analyser/nsrt/date-format.php +++ b/tests/PHPStan/Analyser/nsrt/date-format.php @@ -1,4 +1,4 @@ -= 8.0 namespace DateFormatReturnType; diff --git a/tests/PHPStan/Analyser/nsrt/native-expressions.php b/tests/PHPStan/Analyser/nsrt/native-expressions.php index abe041686a6..9af55763ddc 100644 --- a/tests/PHPStan/Analyser/nsrt/native-expressions.php +++ b/tests/PHPStan/Analyser/nsrt/native-expressions.php @@ -1,4 +1,4 @@ -= 8.0 namespace NativeExpressions; diff --git a/tests/PHPStan/Analyser/nsrt/preg_split.php b/tests/PHPStan/Analyser/nsrt/preg_split.php index 210a467372a..5980f4ad129 100644 --- a/tests/PHPStan/Analyser/nsrt/preg_split.php +++ b/tests/PHPStan/Analyser/nsrt/preg_split.php @@ -1,4 +1,4 @@ -= 8.0 namespace PregSplit; diff --git a/tests/PHPStan/Build/RequiredPhpVersionCommentTest.php b/tests/PHPStan/Build/RequiredPhpVersionCommentTest.php index 5af1af0dc0b..9adde3a4c36 100644 --- a/tests/PHPStan/Build/RequiredPhpVersionCommentTest.php +++ b/tests/PHPStan/Build/RequiredPhpVersionCommentTest.php @@ -123,6 +123,9 @@ public static function dataDetectedVersion(): iterable yield 'enum' => [' [' [' [' [' [' [' [' ['= 8.0 namespace Bug5760; diff --git a/tests/PHPStan/Rules/Functions/data/bug-6448.php b/tests/PHPStan/Rules/Functions/data/bug-6448.php index c2529c8713b..d08399fcad2 100644 --- a/tests/PHPStan/Rules/Functions/data/bug-6448.php +++ b/tests/PHPStan/Rules/Functions/data/bug-6448.php @@ -1,4 +1,4 @@ -= 8.0 namespace Bug6448; diff --git a/tests/PHPStan/Rules/Functions/data/bug-7138.php b/tests/PHPStan/Rules/Functions/data/bug-7138.php index 28b6db70cfc..ed10202d706 100644 --- a/tests/PHPStan/Rules/Functions/data/bug-7138.php +++ b/tests/PHPStan/Rules/Functions/data/bug-7138.php @@ -1,4 +1,4 @@ -= 8.0 namespace Bug7138; diff --git a/tests/PHPStan/Rules/Functions/data/bug-9652.php b/tests/PHPStan/Rules/Functions/data/bug-9652.php index fa0c827443a..2023c941446 100644 --- a/tests/PHPStan/Rules/Functions/data/bug-9652.php +++ b/tests/PHPStan/Rules/Functions/data/bug-9652.php @@ -1,4 +1,4 @@ -= 8.0 namespace Bug9652; diff --git a/tests/PHPStan/Rules/Methods/data/bug-11663.php b/tests/PHPStan/Rules/Methods/data/bug-11663.php index ac2ed03a93f..f21aa5f0cce 100644 --- a/tests/PHPStan/Rules/Methods/data/bug-11663.php +++ b/tests/PHPStan/Rules/Methods/data/bug-11663.php @@ -1,4 +1,4 @@ -= 8.0 namespace Bug11663; diff --git a/tests/PHPStan/Rules/Methods/data/bug-12558.php b/tests/PHPStan/Rules/Methods/data/bug-12558.php index 88a82249241..c501c4137d6 100644 --- a/tests/PHPStan/Rules/Methods/data/bug-12558.php +++ b/tests/PHPStan/Rules/Methods/data/bug-12558.php @@ -1,4 +1,4 @@ -= 8.0 namespace Bug12558; diff --git a/tests/PHPStan/Rules/Methods/data/bug-12884.php b/tests/PHPStan/Rules/Methods/data/bug-12884.php index 20ec2cac5fb..4955bd0f77b 100644 --- a/tests/PHPStan/Rules/Methods/data/bug-12884.php +++ b/tests/PHPStan/Rules/Methods/data/bug-12884.php @@ -1,4 +1,4 @@ -= 8.0 namespace Bug12884; diff --git a/tests/PHPStan/Rules/Methods/data/bug-14617.php b/tests/PHPStan/Rules/Methods/data/bug-14617.php index d8e81076d40..0ad5533fc06 100644 --- a/tests/PHPStan/Rules/Methods/data/bug-14617.php +++ b/tests/PHPStan/Rules/Methods/data/bug-14617.php @@ -1,4 +1,4 @@ -= 8.0 namespace Bug14617; diff --git a/tests/PHPStan/Rules/Methods/data/bug-8071.php b/tests/PHPStan/Rules/Methods/data/bug-8071.php index 2acbb838ca1..60793d5fa55 100644 --- a/tests/PHPStan/Rules/Methods/data/bug-8071.php +++ b/tests/PHPStan/Rules/Methods/data/bug-8071.php @@ -1,4 +1,4 @@ -= 8.0 namespace Bug8071; diff --git a/tests/PHPStan/Rules/Properties/data/invalid-callable-property-type.php b/tests/PHPStan/Rules/Properties/data/invalid-callable-property-type.php index 053c0bfb1cc..8deca5ff92e 100644 --- a/tests/PHPStan/Rules/Properties/data/invalid-callable-property-type.php +++ b/tests/PHPStan/Rules/Properties/data/invalid-callable-property-type.php @@ -1,4 +1,4 @@ -= 8.0 namespace InvalidCallablePropertyType; diff --git a/tests/PHPStan/Rules/Types/data/invalid-union-with-never.php b/tests/PHPStan/Rules/Types/data/invalid-union-with-never.php index d959067f894..00103eceaf9 100644 --- a/tests/PHPStan/Rules/Types/data/invalid-union-with-never.php +++ b/tests/PHPStan/Rules/Types/data/invalid-union-with-never.php @@ -1,4 +1,4 @@ -= 8.0 namespace InvalidUnionWithNever; diff --git a/tests/PHPStan/Rules/Types/data/invalid-union-with-void.php b/tests/PHPStan/Rules/Types/data/invalid-union-with-void.php index 8744da8a104..fee0b54ffa0 100644 --- a/tests/PHPStan/Rules/Types/data/invalid-union-with-void.php +++ b/tests/PHPStan/Rules/Types/data/invalid-union-with-void.php @@ -1,4 +1,4 @@ -= 8.0 namespace InvalidUnionWithVoid;