Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better type inference and type checking for large union types used in array keys/values #9022

Commits on Dec 29, 2022

  1. Better type inference and type checking for large union types used in…

    … array keys/values
    
    Fixes vimeo#8983
    
    This patch adds a basic test showing that, when reaching a union type with 30 elements
    or more, Psalm used to fail with an error, because the large union type got simplified
    into a more general type as part of performance optimizations done in `TypeCombiner::combine()`.
    
    This means that a type like `array<1|2|3|(etcetera...)|100, mixed>` was internally
    simplified to `array<int, mixed>`, after reaching 30 elements or more, which in turn
    led to problems and confusing errors when large union types are in play.
    
    Such union types are relatively common in lookup-table-alike value objects.
    
    By removing the hardcoded call-time limit of `30` types to be combined, we hereby
    rely on the default `TypeCombiner::combine()` limit of `500` items, which is more
    healthy.
    
    This may come with some performance implications, but it is worth trying out, for
    now.
    
    Further parameters passed to `TypeCombiner::combine()` that were already matching
    parameter default values were also omitted from the call-sites.
    Ocramius committed Dec 29, 2022
    Configuration menu
    Copy the full SHA
    e6600fe View commit details
    Browse the repository at this point in the history