Skip to content

[TypeDeclarationDocblocks] Guard DocblockVarArrayFromPropertyDefaultsRector against unsound narrowing - #8435

Open
TomasVotruba wants to merge 1 commit into
mainfrom
tv/docblock-var-property-defaults-guard
Open

[TypeDeclarationDocblocks] Guard DocblockVarArrayFromPropertyDefaultsRector against unsound narrowing#8435
TomasVotruba wants to merge 1 commit into
mainfrom
tv/docblock-var-property-defaults-guard

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Two cases produced a @var narrower than the values actually stored in the property.

Non-private property - a child class can reassign it with a wider type that is invisible from the declaring class:

Property AbstractMauticTestCase::$configParams (array<string, bool|string>)
does not accept array<string, bool|int|string>.

Empty nested array default - e.g. ['create' => [], 'update' => []] generalizes to never[], which then rejects every real value assigned later:

Property ExampleSyncDataExchange::$payload (array<string, never[]>)
does not accept array<string, array<array<string, mixed>>>.

Restrict to private properties and skip empty nested array defaults. The existing array_union_generic_same_type fixture used a protected property; converted to private to keep the transform meaningful.

…Rector against unsound narrowing

Two cases produced a @var narrower than the values actually stored:

- non-private property: a child class can reassign it with a wider type
  that is invisible from the declaring class, so restrict to private
- empty nested array default (e.g. ['create' => [], 'update' => []]):
  generalizes to never[], which then rejects every real value assigned later
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant