From bfded43614b3b9141ee1ef7298a7e20ba640ef24 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 28 Dec 2022 17:26:25 +0100 Subject: [PATCH] Ensure that `explode($d, lowercase-string)` produces `list` types This specific distinction seems to be very important for Psalm, as `explode()` and `lowercase-string` are used aggressively across the codebase. Also, this change expands the baseline by a few entries, since some of the code locations instide Psalm itself have un-checked list destructuring operations, as well as array access calls on potentially undefined array keys produced by `explode()`, which were previously just `list`, and are now `array{0: string, 1?: string}`, which is a bit more precise. --- psalm-baseline.xml | 14 ++++++++--- stubs/CoreGenericFunctions.phpstub | 40 ++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 427084475..562b94c11 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + $comment_block->tags['variablesfrom'][0] @@ -296,6 +296,12 @@ $b[$y] + + + $exploded[1] + $url + + $stmt->props[0] @@ -379,9 +385,9 @@ $fixed_type_tokens[$i - 1] - + $source_param_string - + @@ -695,6 +701,8 @@ allFloatLiterals allFloatLiterals + hasLowercaseString + hasLowercaseString diff --git a/stubs/CoreGenericFunctions.phpstub b/stubs/CoreGenericFunctions.phpstub index 9842d04b1..ccd8f015e 100644 --- a/stubs/CoreGenericFunctions.phpstub +++ b/stubs/CoreGenericFunctions.phpstub @@ -728,18 +728,38 @@ function join($separator, array $array = []): string * @param non-empty-string $separator * * @return ( - * $limit is int - * ? array - * : ( - * $limit is int<0, 1> - * ? array{string} + * $string is lowercase-string + * ? ( + * $limit is int + * ? array * : ( - * $limit is 2 - * ? array{0: string, 1?: string} + * $limit is int<0, 1> + * ? array{lowercase-string} * : ( - * $limit is 3 - * ? array{0: string, 1?: string, 2?: string} - * : non-empty-list + * $limit is 2 + * ? array{0: lowercase-string, 1?: lowercase-string} + * : ( + * $limit is 3 + * ? array{0: lowercase-string, 1?: lowercase-string, 2?: lowercase-string} + * : non-empty-list + * ) + * ) + * ) + * ) + * : ( + * $limit is int + * ? array + * : ( + * $limit is int<0, 1> + * ? array{string} + * : ( + * $limit is 2 + * ? array{0: string, 1?: string} + * : ( + * $limit is 3 + * ? array{0: string, 1?: string, 2?: string} + * : non-empty-list + * ) * ) * ) * )