Skip to content

Commit

Permalink
List refactoring v5 (#8820)
Browse files Browse the repository at this point in the history
* Squash

* Remove BC break

* Suppress

* Possibly fix

* Fixes

* Fix test

* Trigger build

* Update psl

* Update psl

* Fixes

* Fixes

* Cleanup

* fix

* Fix build

* Do not consider never when getting the max count

* Add assertion

* Cleanup

* Fix

* Cleanup
  • Loading branch information
danog committed Dec 13, 2022
1 parent 794ca93 commit cca2767
Show file tree
Hide file tree
Showing 104 changed files with 2,094 additions and 1,681 deletions.
9 changes: 9 additions & 0 deletions UPGRADING.md
@@ -1,3 +1,12 @@
# Upgrading from Psalm 5 to Psalm 6
## Changed

- [BC] Switched the internal representation of `list<T>` and `non-empty-list<T>` from the TList and TNonEmptyList classes to an unsealed list shape: the TList, TNonEmptyList and TCallableList classes were removed.
Nothing will change for users: the `list<T>` and `non-empty-list<T>` syntax will remain supported and its semantics unchanged.
Psalm 5 already deprecates the `TList`, `TNonEmptyList` and `TCallableList` classes: use `\Psalm\Type::getListAtomic`, `\Psalm\Type::getNonEmptyListAtomic` and `\Psalm\Type::getCallableListAtomic` to instantiate list atomics, or directly instantiate TKeyedArray objects with `is_list=true` where appropriate.

- [BC] The only optional boolean parameter of `TKeyedArray::getGenericArrayType` was removed, and was replaced with a string parameter with a different meaning.

# Upgrading from Psalm 4 to Psalm 5
## Changed

Expand Down
138 changes: 0 additions & 138 deletions bin/psl-psalm-plugin.diff

This file was deleted.

16 changes: 9 additions & 7 deletions bin/test-with-real-projects.sh
Expand Up @@ -30,15 +30,16 @@ collections)
;;

psl)
# For circleCI
export PHP_EXTENSION_INTL=1
export PHP_EXTENSION_BCMATH=1

git clone git@github.com:psalm/endtoend-test-psl.git
cd endtoend-test-psl
git checkout 1.9.x-array
composer require --dev php-standard-library/psalm-plugin:^1.1.4 --ignore-platform-reqs
cd vendor/php-standard-library/psalm-plugin
patch -p1 < $SCRIPT_DIR/psl-psalm-plugin.diff
cd ../../../
cd tools/phpbench && composer install --ignore-platform-reqs && cd ../..
"$PSALM" --monochrome --config=tools/psalm/psalm.xml
git checkout 2.3.x
composer install
"$PSALM" --monochrome -c config/psalm.xml
"$PSALM" --monochrome -c config/psalm.xml tests/static-analysis
;;

laravel)
Expand All @@ -47,6 +48,7 @@ laravel)
composer install
"$PSALM" --monochrome
;;

*)
echo "Usage: test-with-real-projects.sh {phpunit|collections|laravel|psl}"
exit 1
Expand Down
6 changes: 2 additions & 4 deletions docs/running_psalm/plugins/plugins_type_system.md
Expand Up @@ -165,8 +165,6 @@ if (true === $first) {

`TArray` - denotes a simple array of the form `array<TKey, TValue>`. It expects an array with two elements, both union types.

`TList` - Represents an array that has some particularities: its keys are integers, they start at 0, they are consecutive and go upwards (no negative int)

`TNonEmptyArray` - as above, but denotes an array known to be non-empty.

`TKeyedArray` represents an 'object-like array' - an array with known keys.
Expand All @@ -176,6 +174,8 @@ $x = ["a" => 1, "b" => 2]; // is TKeyedArray, array{a: int, b: int}
$y = rand(0, 1) ? ["a" => null] : ["a" => 1, "b" => "b"]; // is TKeyedArray with optional keys/values, array{a: ?int, b?: string}
```

This type is also used to represent lists (instead of the now-deprecated `TList` type).

Note that not all associative arrays are considered object-like. If the keys are not known, the array is treated as a mapping between two types.

``` php
Expand All @@ -185,8 +185,6 @@ foreach (range(1,1) as $_) $a[(string)rand(0,1)] = rand(0,1); // array<string,in

`TCallableArray` - denotes an array that is _also_ `callable`.

`TCallableList` - denotes a list that is _also_ `callable`.

`TCallableKeyedArray` - denotes an object-like array that is _also_ `callable`.

`TClassStringMap` - Represents an array where the type of each value is a function of its string key value
Expand Down

0 comments on commit cca2767

Please sign in to comment.