You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Big array are too much simplified since 1.8.4 #7963
I understood that some changes/simplifications were introduced to array in 1.8.4 because 1.8.3 were too slow
but the following code was fast and were working in 1.8.2 (and 1.8.3) so I assume that under some conditions, it could be still possible to not over-simplified this array.
I dumped the type in 1.8.2 and the array was not simplified.
I see two solutions to my issue
Find a way to not break performances and still avoid to simplified the array
Simplified the array but preferred array-shape array{} over array, this would be simplified to
Did PHPStan help you today? Did it make you happy in any way?
In this particular example, it should be relatively easy to collapse the union produced by the ternaries back into a single array shape. The two array shapes produced by the two branches of the ternaries only ever differ by one single element. Keeping unions as array{...}|array{...} only makes sense when there are at least two differences, such as to keep information about their correlation (or entanglement if you prefer).
"If you want a fast PHPStan, you can use a lower constant, but be aware array are degraded quickly".
"If you want a precise PHPStan, you can use a bigger constant, but be aware it can be slow".
@@ @@
-9: PHPDoc tag @var for constant Octicons::Data with type array<string, array{width: int, height: int, path: string}> is not subtype of value non-empty-array<'accessibility'|'alert'|'apps'|'archive'|'arrow-both'|'arrow-down'|'arrow-left'|'arrow-right'|'arrow-switch'|'arrow-up'|'beaker'|'bell'|'bell-fill'|'bell-slash'|'blocked'|'bold'|'book'|'bookmark'|'bookmark-slash'|'briefcase'|'broadcast'|'browser'|'bug'|'calendar'|'check'|'check-circle'|'check-circle-fill'|'checklist'|'chevron-down'|'chevron-left'|'chevron-right'|'chevron-up'|'circle'|'circle-slash'|'clock'|'cloud'|'cloud-offline'|'code'|'code-of-conduct'|'code-review'|'code-square'|'codescan'|'codescan-checkmark'|'codespaces'|'columns'|'comment'|'comment-discussion'|'container'|'copilot'|'copilot-error'|'copilot-warning'|'copy'|'cpu'|'credit-card'|'cross-reference'|'dash'|'database'|'dependabot'|'desktop-download'|'device-camera'|'device-camera-video'|'device-desktop'|'device-mobile'|'diamond'|'diff'|'diff-added'|'diff-ignored'|'diff-modified'|'diff-removed'|'diff-renamed'|'dot'|'dot-fill'|'download'|'duplicate'|'ellipsis'|'eye'|'eye-closed'|'facebook'|'feed-discussion'|'feed-forked'|'feed-heart'|'feed-merged'|'feed-person'|'feed-repo'|'feed-rocket'|'feed-star'|'feed-tag'|'feed-trophy'|'file'|'file-added'|'file-badge'|'file-binary'|'file-code'|'file-diff'|'file-directory'|'file-directory-fill'|'file-directory-open…'|'file-moved'|'file-removed'|'file-submodule'|'file-symlink-file'|'file-zip'|'filter'|'flame'|'fold'|'fold-down'|'fold-up'|'gear'|'gift'|'git-branch'|'git-commit'|'git-compare'|'git-merge'|'git-pull-request'|'git-pull-request…'|'git-pull-request…'|'globe'|'grabber'|'graph'|'hash'|'heading'|'heart'|'heart-fill'|'history'|'home'|'horizontal-rule'|'hourglass'|'hubot'|'id-badge'|'image'|'inbox'|'infinity'|'info'|'issue-closed'|'issue-draft'|'issue-opened'|'issue-reopened'|'italic'|'iterations'|'kebab-horizontal'|'key'|'key-asterisk'|'law'|'light-bulb'|'link'|'link-external'|'linux'|'list-ordered'|'list-unordered'|'location'|'lock'|'log'|'logo-gist'|'logo-github'|'macos'|'mail'|'mark-github'|'markdown'|'megaphone'|'mention'|'meter'|'milestone'|'mirror'|'moon'|'mortar-board'|'multi-select'|'mute'|'no-entry'|'north-star'|'note'|'number'|'organization'|'package'|'package-dependencies'|'package-dependents'|'paintbrush'|'paper-airplane'|'paste'|'pencil'|'people'|'person'|'person-add'|'person-fill'|'pin'|'play'|'plug'|'plus'|'plus-circle'|'project'|'pulse'|'question'|'quote'|'reply'|'repo'|'repo-clone'|'repo-deleted'|'repo-forked'|'repo-locked'|'repo-pull'|'repo-push'|'repo-template'|'report'|'rocket'|'rows'|'rss'|'ruby'|'screen-full'|'screen-normal'|'search'|'server'|'share'|'share-android'|'shield'|'shield-check'|'shield-lock'|'shield-x'|'sidebar-collapse'|'sidebar-expand'|'sign-in'|'sign-out'|'single-select'|'skip'|'sliders'|'smiley'|'sort-asc'|'sort-desc'|'square'|'square-fill'|'squirrel'|'stack'|'star'|'star-fill'|'steam'|'steamdb'|'steamdeck'|'steamdeck_playable'|'steamdeck…'|'steamdeck_verified'|'steamworks'|'stop'|'stopwatch'|'strikethrough'|'sun'|'sync'|'tab-external'|'table'|'tag'|'tasklist'|'telescope'|'telescope-fill'|'terminal'|'three-bars'|'thumbsdown'|'thumbsup'|'tools'|'trash'|'triangle-down'|'triangle-left'|'triangle-right'|'triangle-up'|'trophy'|'twitch'|'twitter'|'typography'|'unfold'|'unlock'|'unmute'|'unverified'|'upload'|'verified'|'versions'|'video'|'webhook'|'windows'|'workflow'|'x'|'x-circle'|'x-circle-fill'|'youtube'|'zap', non-empty-array<literal-string&non-falsy-string, int|(literal-string&non-falsy-string)>>.
+No errors
Activity
xPaw commentedon Sep 8, 2022
I'm seeing a similar issue with a big array: https://phpstan.org/r/125b4137-6f1e-46c4-bb2f-7e281c061d45
For this particular array, if I change all the
pathto an empty string, it no longer errors.ondrejmirtes commentedon Sep 8, 2022
Someone needs to figure out how to keep PHPStan fast and these types more precise.
jlherren commentedon Sep 9, 2022
Here's a much smaller example to help investigating this more easily, however I'm not 100% sure it's the exact same issue.
https://phpstan.org/r/b6a055a2-00fc-4151-a500-c62506bbdcf9
In this particular example, it should be relatively easy to collapse the union produced by the ternaries back into a single array shape. The two array shapes produced by the two branches of the ternaries only ever differ by one single element. Keeping unions as
array{...}|array{...}only makes sense when there are at least two differences, such as to keep information about their correlation (or entanglement if you prefer).VincentLanglet commentedon Sep 18, 2022
I'm not sure which commit introduce the degradation of the array, if it's phpstan/phpstan-src@0cc87f3 or another.
But if this is related to some constant like https://github.com/phpstan/phpstan-src/blob/8250448ceac7586cf556b6e9c7858b50f6aa50e7/src/Type/Constant/ConstantArrayTypeBuilder.php#L25
a solution could be to make this constant configurable.
"If you want a fast PHPStan, you can use a lower constant, but be aware array are degraded quickly".
"If you want a precise PHPStan, you can use a bigger constant, but be aware it can be slow".
phpstan-bot commentedon Sep 19, 2022
@xPaw After the latest push in 1.8.x, PHPStan now reports different result with your code snippet:
phpstan-bot commentedon Sep 19, 2022
@jlherren After the latest push in 1.8.x, PHPStan now reports different result with your code snippet:
Full report
VincentLanglet commentedon Sep 19, 2022
The original issue is not solved, but the others two examples are solved by phpstan/phpstan-src@43d3652...bd57fc5
Do you want to add a regression test @ondrejmirtes @rvanvelzen ? (I can do it if the test if wanted)
ondrejmirtes commentedon Sep 22, 2022
Fixed, thanks: phpstan/phpstan-src@5f1a4a5
github-actions commentedon Oct 24, 2022
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.