Skip to content

fix(reconciler): an offset under one of several literal keys is the value of those keys - #14646

Merged
orklah merged 3 commits into
vimeo:masterfrom
jirkace:fix/9714-offset-under-literal-keys
Nov 23, 2026
Merged

orklah merged 3 commits into
vimeo:masterfrom
jirkace:fix/9714-offset-under-literal-keys

Conversation

@jirkace

@jirkace jirkace commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

After isset($array[$k]) / !empty($array[$k]) where $k is one of several literal keys, $array[$k] is every value the array can hold instead of the values under those keys.

Before

<?php
function getUserIps(): string {
    $ips = [];
    foreach (["REMOTE_ADDR", "HTTP_X_FORWARDED_FOR", "HTTP_CLIENT_IP"] as $k) {
        if (isset($_SERVER[$k])) {
            $ips[] = $_SERVER[$k]; // $ips: non-empty-list<non-empty-list<string>|scalar>
        }
    }

    return implode(", ", $ips); // InvalidArgument
}

After

            $ips[] = $_SERVER[$k]; // $ips: non-empty-list<non-empty-string>
    return implode(", ", $ips); // no issue

Fixes #9714

…alue of those keys vimeo#9714

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jirkace

jirkace commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Behaviour change

  • After an assertion on $array[$k] (isset, !empty, ??, …) where $k holds one of several literal keys, the reconciled $array[$k] is the union of the shape's items under those keys. Before, it was every value the array could hold (getGenericValueType()), only a single literal key was looked up. A key a sealed shape doesn't list is skipped (nothing can be under it).
  • When the shape may not have one of the keys (an unsealed shape not listing it), the result is still every value of the array, as before. Taking the rest type for that key instead changed a loop over literal keys in drupal (GenerateTheme.php:322) to report a PossiblyUndefinedStringArrayOffset, so it is left out.
  • Corpora (laravel, symfony, drupal) and self-analysis: no change.

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: decreased

Project Memory (MB) Wall (s) Issues Weighted (types) Taint Dead code
✅ laravel 1 772 74.1 25 784 53 058 743 0
✅ symfony 3 619 165.5 $\color{gray}{\textsf{-4.1\%}}$ 51 753 $\color{red}{\textsf{+6}}$ $\color{green}{\textsf{-8}}$ 100 575 $\color{green}{\textsf{-8}}$ 1 582 0
✅ doctrine-orm 380 18.2 $\color{gray}{\textsf{+0.8\%}}$ 3 453 $\color{red}{\textsf{+1}}$ $\color{green}{\textsf{-6}}$ 6 197 $\color{green}{\textsf{-18}}$ 0 0
✅ psl 618 23.3 $\color{gray}{\textsf{-0.3\%}}$ 1 390 5 613 1 0
✅ phpunit 456 13.0 $\color{gray}{\textsf{-2.0\%}}$ 1 735 3 418 18 0
✅ php-parser 226 8.6 $\color{gray}{\textsf{-0.7\%}}$ 17 116 21 187 0 0
✅ tempest 898 24.9 $\color{gray}{\textsf{+3.9\%}}$ 5 093 10 567 275 0
✅ amphp-amp 48 1.0 re-run 29 49 0 0
✅ webmozarts-assert 273 2.9 $\color{gray}{\textsf{+1.0\%}}$ 575 2 714 0 0
✅ guzzle-promises 46 1.1 $\color{gray}{\textsf{-4.3\%}}$ 156 436 2 0
✅ monolog 136 3.8 $\color{gray}{\textsf{+2.2\%}}$ 918 2 491 11 0
✅ drupal 4 844 199.4 $\color{gray}{\textsf{+0.9\%}}$ 97 851 $\color{gray}{\textsf{+0}}$ $\color{green}{\textsf{-3}}$ 169 763 $\color{green}{\textsf{-7}}$ 575 0
✅ wordpress 2 042 173.5 $\color{gray}{\textsf{+0.9\%}}$ 143 511 $\color{red}{\textsf{+1}}$ $\color{green}{\textsf{-6}}$ 678 178 $\color{green}{\textsf{-12}}$ 461 1
Total 15 358 709.5 $\color{gray}{\textsf{-0.4\%}}$ 349 364 $\color{red}{\textsf{+8}}$ $\color{green}{\textsf{-23}}$ 1 054 246 $\color{green}{\textsf{-45}}$ 3 668 1
How to read this table
  • Memory: Psalm's own peak figure, threads=1. More than +5 % fails, unless the PR changes composer.json.
  • Wall: base and head run on the same runner; ±10 % is noise. Above +10 % warns, never fails. re-run: a reversed second run was taken and the faster kept.
  • Issues: head count over all categories, then $\color{red}{\textsf{+added}}$ $\color{green}{\textsf{-removed}}$ against base.
  • Weighted (types): type issues weighted by error level (levels 1–8 as is, always-errors 10, strictness checks 1). Taint and dead-code issues are not weighed. The projects' own code is pinned and their dependencies resolve identically for base and head, so a change means Psalm reports more, fewer or differently serious issues. A rise is not necessarily a regression.
  • Taint: head count of Tainted* issues, then $\color{orange}{\textsf{+added}}$ $\color{orange}{\textsf{-removed}}$ against base. Both are orange as either direction needs review: more can be new detection or false positives, fewer can be fixed false positives or lost detection.
  • Dead code: head count of unused-code issues, shown only when a run reported some (findUnusedCode). More is red, fewer is green.
  • Total: sum over the projects compared on both sides. Its wall time warns above +5 % (±5 % is noise); the other thresholds apply per project.
  • Colors: $\color{red}{\textsf{red}}$ past a fail or warn threshold (or more issues), $\color{green}{\textsf{green}}$ an improvement past noise (or fewer issues), $\color{orange}{\textsf{orange}}$ needs review, $\color{gray}{\textsf{gray}}$ noise.
  • Performance: regressed if a head run crashed or timed out or a memory or wall delta is red, else improved if one is green, else unchanged. Its icon is the check result: ❌ fail · ⚠️ warn · ✅ pass; the icon next to each project is that project's result, 💥 = not comparable: base crashed or timed out (counts as ⚠️).
  • Types (heading): direction of the total weighted change, increased · decreased · unchanged. Taint and Dead code (heading): added and removed counts, present only when non-zero. Informational, never fails the check.
✅ symfony: issues +6 −8

Memory 3 619 → 3 619 MB (<0.1 %) · Wall 172.6 → 165.5 s (−4.1 %)

Weighted 100 583 → 100 575 (−8, −0.01 %): L4 −2

Issue type added removed
InvalidScalarArgument 5 7
PossiblyInvalidArgument 0 1
PossiblyNullArgument 1 0

Changed in place (2)

@​@​ src/Symfony/Component/HttpClient/HttpClientTrait.php:714 @​@​
- PossiblyInvalidArgument: Argument 3 of preg_replace_callback expects array<array-key, float|int|string>|string, but possibly different type int|null|string provided
+ PossiblyNullArgument:    Argument 3 of preg_replace_callback cannot be null, possibly null value provided

@​@​ src/Symfony/Component/Mime/Crypto/PgpProcess.php:50 InvalidScalarArgument @​@​
- Argument 1 of PgpProcess::__construct expects string, but possibly undefined bool|float|null|string provided
- Argument 2 of PgpProcess::__construct expects string, but possibly undefined bool|float|null|string provided
- Argument 3 of PgpProcess::__construct expects string, but possibly undefined bool|float|null|string provided
- Argument 4 of PgpProcess::__construct expects string, but possibly undefined bool|float|null|string provided
- Argument 5 of PgpProcess::__construct expects float|null, but possibly undefined bool|float|null|string provided
+ Argument 1 of PgpProcess::__construct expects string, but possibly undefined float|null|string provided
+ Argument 2 of PgpProcess::__construct expects string, but possibly undefined float|null|string provided
+ Argument 3 of PgpProcess::__construct expects string, but possibly undefined float|null|string provided
+ Argument 4 of PgpProcess::__construct expects string, but possibly undefined float|null|string provided
+ Argument 5 of PgpProcess::__construct expects float|null, but possibly undefined float|null|string provided

Removed (2)

  • src/Symfony/Component/HtmlSanitizer/TextSanitizer/UrlSanitizer.php:210 InvalidScalarArgument (error): Argument 1 of rawurldecode expects string, but int|string provided
  • src/Symfony/Component/HttpClient/HttpClientTrait.php:708 InvalidScalarArgument (error): Argument 1 of str_contains expects string, but int|string provided
✅ doctrine-orm: issues +1 −6

Memory 380 → 380 MB (<0.1 %) · Wall 18.1 → 18.2 s (+0.8 %)

Weighted 6 215 → 6 197 (−18, −0.29 %): L3 −4 · L6 −1

Issue type added removed
InvalidPropertyAssignmentValue 0 1
MixedArgumentTypeCoercion 1 0
MixedStringOffsetAssignment 0 1
PossiblyInvalidArgument 0 1
PossiblyInvalidArrayAssignment 0 1
PossiblyInvalidArrayOffset 0 1
PossiblyInvalidIterator 0 1

Changed in place (1)

@​@​ src/Mapping/ClassMetadataFactory.php:531 @​@​
- PossiblyInvalidArgument:   …<int|string, array<string, mixed>>, but possibly different type array<array-key, mixed>|bool|string provided
+ MixedArgumentTypeCoercion: …<int|string, array<string, mixed>>, but parent type array<array-key, mixed> provided

Removed (5)

  • src/Mapping/ClassMetadataFactory.php:526 PossiblyInvalidIterator (error): Cannot iterate over bool
  • src/Mapping/ClassMetadataFactory.php:542 InvalidPropertyAssignmentValue (error): $subClass->table with declared type 'array{indexes?: array<array-key, mixed>, name: string, options?: array<string, mixed>, quoted?: bool, schema?: string, uniqueConstraints?: array<array-key, mixed>}' cannot be assign…
  • src/Mapping/ClassMetadataFactory.php:542 MixedStringOffsetAssignment (error): Right-hand-side of string offset assignment cannot be mixed
  • src/Mapping/ClassMetadataFactory.php:542 PossiblyInvalidArrayAssignment (error): Cannot access array value on non-array variable $subClass->table[$indexType][$indexName] of type bool
  • src/Mapping/ClassMetadataFactory.php:542 PossiblyInvalidArrayOffset (error): Cannot access value on variable $subClass->table[$indexType][$indexName] using a string offset, expecting int
✅ drupal: issues +0 −3

Memory 4 844 → 4 844 MB (<0.1 %) · Wall 197.7 → 199.4 s (+0.9 %)

Weighted 169 770 → 169 763 (−7, <0.01 %): L1 −1 · L3 −2

Issue type added removed
MixedArrayAssignment 0 1
PossiblyInvalidArrayAssignment 0 1
PossiblyInvalidArrayOffset 0 1

Removed (3)

  • core/modules/user/src/AccountForm.php:187 MixedArrayAssignment (error): Cannot access array value on mixed variable $form['account'][$key]['#attributes']['autocomplete']
  • core/modules/user/src/AccountForm.php:187 PossiblyInvalidArrayAssignment (error): Cannot access array value on non-array variable $form['account'][$key]['#attributes'] of type -10
  • core/modules/user/src/AccountForm.php:187 PossiblyInvalidArrayOffset (error): Cannot access value on variable $form['account'][$key]['#attributes'] using offset value of '#attributes', expecting -9|-8|-7|-6|-5|-4|-3|-2|-1|0|1|2|3|4|5|6|7|8
✅ wordpress: issues +1 −6

Memory 2 042 → 2 042 MB (<0.1 %) · Wall 172.0 → 173.5 s (+0.9 %)

Weighted 678 190 → 678 178 (−12, <0.01 %): L1 −2 · L3 −2 · L4 −1

Issue type added removed
InvalidScalarArgument 0 1
MixedArgument 0 1
MixedAssignment 0 1
PossiblyInvalidArgument 0 2
PossiblyUndefinedArrayOffset 1 1

Changed in place (1)

@​@​ src/wp-includes/ID3/module.tag.apetag.php:282 PossiblyUndefinedArrayOffset @​@​
- … max>, data_offset: mixed, datalength?: array<array-key, mixed>|int<0, max>|mixed|string, description?: array<array-key, mixed>|int<0, max>|mixed|string, filename: string, flags: array<array-key, mixed>, image_height?: array<array-key, mixed>|int<0, max>|mixed|string, image_mime: '', image_width?: array<array-key, mixed>|int<0, max>|mixed|string, imagetype?: array<array-key, mixed>|int<0, max>|mixed|string, offset: mixed, picturetype?: array<array-key, mixed>|int<0, max>|mixed|string}
+ … max>, data_offset: mixed, datalength?: string, description?: string, filename: string, flags: array<array-key, mixed>, image_height?: string, image_mime: '', image_width?: string, imagetype?: string, offset: mixed, picturetype?: string}

Removed (5)

  • src/wp-admin/includes/image.php:1043 MixedArgument (error): Argument 1 of utf8_encode cannot be float|int|non-empty-list<mixed>|non-empty-mixed|non-falsy-string, expecting string
  • src/wp-admin/includes/image.php:1043 PossiblyInvalidArgument (error): Argument 1 of utf8_encode expects string, but possibly different type float|int|non-empty-list<mixed>|non-empty-mixed|non-falsy-string provided
  • src/wp-includes/ID3/module.audio-video.asf.php:728 PossiblyInvalidArgument (error): Argument 1 of getid3_asf::TrimTerm expects string, but possibly different type float|int|non-falsy-string provided
  • src/wp-includes/ID3/module.tag.apetag.php:329 MixedAssignment (error): Unable to determine the type of this assignment
  • src/wp-includes/pluggable.php:1625 InvalidScalarArgument (error): Argument 1 of strpbrk expects string, but int|string provided

head 4d81dbb · base 71a650b (merge-base) · workflow run

…shape lists is any of its values vimeo#9714

When none of several literal keys is listed by a sealed shape, the
offset was left unknown (`mixed`), where master took the values of the
array as for a key of no known value: monolog's
`isset(self::RFC_5424_LEVELS[$level])` with `$level` one of the `Level`
values got a `MixedAssignment`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jirkace

jirkace commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Behaviour change (addition) and correction, after the perf report of the previous head:

  • monolog Logger.php:343 and :583: the previous head added MixedAssignment (and MixedArgument at :370, :586) for if (\is_int($level) && isset(self::RFC_5424_LEVELS[$level])) { $level = self::RFC_5424_LEVELS[$level]; }. There $level holds several literals (the Level values) and the sealed constant array lists none of them. The previous head skipped every key and left the offset unknown. Master took the values of the array, as for a key of no known value. Fixed in the new commit: when none of several literal keys is listed, the offset is any value of the array, as on master. A single unlisted literal key is unchanged. New test IssetTest::testValidCode@offsetUnderSeveralLiteralKeysNoneOfWhichASealedShapeListsIsItsValue fails on the previous head. offsetUnderOneOfSeveralLiteralKeysIsTheValueOfThoseKeys still passes.
  • Correction: my comment above said "Corpora (laravel, symfony, drupal) and self-analysis: no change". That held for my local subsets only. The perf report on the full projects shows changes, all with narrower types or fewer issues: symfony +6 −8 (the PgpProcess::__construct arguments lose bool, two InvalidScalarArgument are gone, PossiblyInvalidArgument → PossiblyNullArgument for preg_replace_callback()), doctrine-orm +1 −6 (ClassMetadataFactory.php:526/:542 reports gone, one PossiblyInvalidArgument → MixedArgumentTypeCoercion), drupal −3 (AccountForm.php:187).
  • Self-analysis shows only the two local PoolEventLoopDriverTest MixedArgument errors. phpcs is clean. Not run: the full suite (CI runs it) and the benchmark projects.

# Conflicts:
#	tests/TypeReconciliation/IssetTest.php
@orklah orklah added the release:fix The PR will be included in 'Fixes' section of the release notes label Nov 23, 2026
@orklah

orklah commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Thanks @jirkace!

@orklah
orklah merged commit 69023bc into vimeo:master Nov 23, 2026
116 of 119 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:fix The PR will be included in 'Fixes' section of the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect array type recognition

2 participants