Skip to content

Call restricted usage extensions for members accessed on nullable types - #7008

Closed
ondrejmirtes wants to merge 1 commit into
2.3.xfrom
restricted-usage-nullable
Closed

ondrejmirtes wants to merge 1 commit into
2.3.xfrom
restricted-usage-nullable

Conversation

@ondrejmirtes

Copy link
Copy Markdown
Member

Restricted usage rules for methods, properties, class constants, their static and first-class-callable variants, and the deprecated __toString cast rule did not call extensions when the member was accessed on a type such as Foo|null or Foo|false.

The instance rules took class names from getObjectClassNames(), which returns [] for a union with any non-object member. The static rules used FoundTypeResult::getReferencedClasses(), which has the same issue when checkNullables is on. Only $foo?->doFoo() was reported, because the nullsafe call narrows $foo first.

The rules now intersect the type with object before collecting class names. Extensions are still called once per class, so Foo|Bar keeps reporting each class separately. Passing a merged UnionTypeMethodReflection from Scope::getMethodReflection() would hide e.g. a deprecated method that exists on only one member of the union.

Restricted usage rules took class names from getObjectClassNames(), which
returns nothing for unions with non-object members like Foo|null. Strip the
non-object parts first so extensions are still called once per class.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1bc39-a252-73e6-a583-cfe70f1d1c88
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant