From 3791878c3190c8e530e576f860246108bd181015 Mon Sep 17 00:00:00 2001 From: Alies Lapatsin <5278175+alies-dev@users.noreply.github.com> Date: Tue, 23 Jun 2026 13:30:16 +0200 Subject: [PATCH] fix(stubs): allow #[\Override] on properties (PHP 8.5) PHP 8.5 permits #[\Override] on properties (RFC: marking overridden properties), but the bundled stub declared the attribute with TARGET_METHOD only, so Psalm reported a false-positive InvalidAttribute for valid property usage. Add TARGET_PROPERTY to the Override attribute target set. Class constants stay excluded, matching the engine, which rejects #[\Override] on a class constant. The stub loads unconditionally, so the property target applies to every analysis_php_version rather than 8.5+ only. Per-version attribute target sets cannot be expressed through stubs (version stubs are cumulative and a class cannot be redeclared with different flags), and this matches how Psalm already handles other attributes such as Deprecated. Fixes #11890 --- stubs/CoreGenericAttributes.phpstub | 2 +- tests/AttributeTest.php | 38 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/stubs/CoreGenericAttributes.phpstub b/stubs/CoreGenericAttributes.phpstub index d995180815a..665cf95bfac 100644 --- a/stubs/CoreGenericAttributes.phpstub +++ b/stubs/CoreGenericAttributes.phpstub @@ -8,7 +8,7 @@ final class AllowDynamicProperties } /** @psalm-immutable */ -#[Attribute(Attribute::TARGET_METHOD)] +#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_PROPERTY)] final class Override { public function __construct() {} diff --git a/tests/AttributeTest.php b/tests/AttributeTest.php index 66d7f170507..3944723d8cc 100644 --- a/tests/AttributeTest.php +++ b/tests/AttributeTest.php @@ -43,6 +43,32 @@ class Foo {} public function providerValidCodeParse(): iterable { return [ + 'overrideAttributeOnOverriddenMethod' => [ + 'code' => ' [ + 'code' => ' [ 'code' => ' 'InvalidAttribute - src' . DIRECTORY_SEPARATOR . 'somefile.php:11:39 - Attribute Attr cannot be used on a class constant', ], + 'getAttributesOnClassConstantWithOverrideAttribute' => [ + 'code' => 'getAttributes(\Override::class); + ', + 'error_message' => 'InvalidAttribute - src' . DIRECTORY_SEPARATOR . 'somefile.php:8:39 - Attribute Override cannot be used on a class constant', + ], 'getAttributesOnParameterWithNonParameterAttribute' => [ 'code' => '