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

Fix PSL e2e tests #8697

Merged
merged 1 commit into from Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
138 changes: 138 additions & 0 deletions bin/psl-psalm-plugin.diff
@@ -0,0 +1,138 @@
diff --git a/src/EventHandler/Iter/First/FunctionReturnTypeProvider.php b/src/EventHandler/Iter/First/FunctionReturnTypeProvider.php
index 7168824..dfd0a8a 100644
--- a/src/EventHandler/Iter/First/FunctionReturnTypeProvider.php
+++ b/src/EventHandler/Iter/First/FunctionReturnTypeProvider.php
@@ -34,20 +34,20 @@ final class FunctionReturnTypeProvider implements FunctionReturnTypeProviderInte
}

if ($array_argument_type instanceof Type\Atomic\TNonEmptyArray) {
- return clone $array_argument_type->type_params[1];
+ return $array_argument_type->type_params[1];
}

if ($array_argument_type instanceof Type\Atomic\TNonEmptyList) {
- return clone $array_argument_type->type_param;
+ return $array_argument_type->type_param;
}

if ($array_argument_type instanceof Type\Atomic\TKeyedArray) {
// TODO(azjezz): add support for this once psalm starts enforcing the shape order ( if ever ).
//
// foreach ($properties as $property) {
- // return clone $property;
+ // return $property;
// }
- return clone $array_argument_type->getGenericValueType();
+ return $array_argument_type->getGenericValueType();
}

return null;
diff --git a/src/EventHandler/Iter/FirstKey/FunctionReturnTypeProvider.php b/src/EventHandler/Iter/FirstKey/FunctionReturnTypeProvider.php
index f95ebfd..d276046 100644
--- a/src/EventHandler/Iter/FirstKey/FunctionReturnTypeProvider.php
+++ b/src/EventHandler/Iter/FirstKey/FunctionReturnTypeProvider.php
@@ -34,7 +34,7 @@ final class FunctionReturnTypeProvider implements FunctionReturnTypeProviderInte
}

if ($array_argument_type instanceof Type\Atomic\TNonEmptyArray) {
- return clone $array_argument_type->type_params[0];
+ return $array_argument_type->type_params[0];
}

if ($array_argument_type instanceof Type\Atomic\TNonEmptyList) {
@@ -45,9 +45,9 @@ final class FunctionReturnTypeProvider implements FunctionReturnTypeProviderInte
// TODO(azjezz): add support for this once psalm starts enforcing the shape order ( if ever ).
//
// foreach ($properties as $property) {
- // return clone $property;
+ // return $property;
// }
- return clone $array_argument_type->getGenericKeyType();
+ return $array_argument_type->getGenericKeyType();
}

return null;
diff --git a/src/EventHandler/Iter/Last/FunctionReturnTypeProvider.php b/src/EventHandler/Iter/Last/FunctionReturnTypeProvider.php
index 6a7a8c8..5f79bb7 100644
--- a/src/EventHandler/Iter/Last/FunctionReturnTypeProvider.php
+++ b/src/EventHandler/Iter/Last/FunctionReturnTypeProvider.php
@@ -34,11 +34,11 @@ final class FunctionReturnTypeProvider implements FunctionReturnTypeProviderInte
}

if ($array_argument_type instanceof Type\Atomic\TNonEmptyArray) {
- return clone $array_argument_type->type_params[1];
+ return $array_argument_type->type_params[1];
}

if ($array_argument_type instanceof Type\Atomic\TNonEmptyList) {
- return clone $array_argument_type->type_param;
+ return $array_argument_type->type_param;
}

if ($array_argument_type instanceof Type\Atomic\TKeyedArray) {
@@ -50,8 +50,8 @@ final class FunctionReturnTypeProvider implements FunctionReturnTypeProviderInte
// $last_property = $property;
// }
//
- // return clone $last_property;
- return clone $array_argument_type->getGenericValueType();
+ // return $last_property;
+ return $array_argument_type->getGenericValueType();
}

return null;
diff --git a/src/EventHandler/Iter/LastKey/FunctionReturnTypeProvider.php b/src/EventHandler/Iter/LastKey/FunctionReturnTypeProvider.php
index 7e98609..19abf16 100644
--- a/src/EventHandler/Iter/LastKey/FunctionReturnTypeProvider.php
+++ b/src/EventHandler/Iter/LastKey/FunctionReturnTypeProvider.php
@@ -34,7 +34,7 @@ final class FunctionReturnTypeProvider implements FunctionReturnTypeProviderInte
}

if ($array_argument_type instanceof Type\Atomic\TNonEmptyArray) {
- return clone $array_argument_type->type_params[0];
+ return $array_argument_type->type_params[0];
}

if ($array_argument_type instanceof Type\Atomic\TNonEmptyList) {
@@ -50,8 +50,8 @@ final class FunctionReturnTypeProvider implements FunctionReturnTypeProviderInte
// $last_property = $property;
// }
//
- // return clone $last_property;
- return clone $array_argument_type->getGenericKeyType();
+ // return $last_property;
+ return $array_argument_type->getGenericKeyType();
}

return null;
diff --git a/src/EventHandler/Type/Optional/FunctionReturnTypeProvider.php b/src/EventHandler/Type/Optional/FunctionReturnTypeProvider.php
index 2c0fbb3..896f434 100644
--- a/src/EventHandler/Type/Optional/FunctionReturnTypeProvider.php
+++ b/src/EventHandler/Type/Optional/FunctionReturnTypeProvider.php
@@ -28,9 +28,6 @@ final class FunctionReturnTypeProvider implements FunctionReturnTypeProviderInte
return null;
}

- $clone = clone $argument_type;
- $clone->possibly_undefined = true;
-
- return $clone;
+ return $argument_type->setPossiblyUndefined(true);
}
}
diff --git a/src/EventHandler/Type/Shape/FunctionReturnTypeProvider.php b/src/EventHandler/Type/Shape/FunctionReturnTypeProvider.php
index 3650a1a..b51bf63 100644
--- a/src/EventHandler/Type/Shape/FunctionReturnTypeProvider.php
+++ b/src/EventHandler/Type/Shape/FunctionReturnTypeProvider.php
@@ -57,8 +57,9 @@ final class FunctionReturnTypeProvider implements FunctionReturnTypeProviderInte
return null;
}

- $property_type = clone $type->type_params[0];
- $property_type->possibly_undefined = $value->possibly_undefined;
+ $property_type = $type->type_params[0]->setPossiblyUndefined(
+ $value->possibly_undefined
+ );

$properties[$name] = $property_type;
}
4 changes: 4 additions & 0 deletions bin/test-with-real-projects.sh
Expand Up @@ -4,6 +4,7 @@ set -e
set -x

SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
SCRIPT_DIR="$(realpath "$SCRIPT_DIR")"
PSALM="$(readlink -f "$SCRIPT_DIR/../psalm")"
PSALM_PHAR="$(readlink -f "$SCRIPT_DIR/../build/psalm.phar")"

Expand Down Expand Up @@ -33,6 +34,9 @@ psl)
cd endtoend-test-psl
git checkout 1.9.x
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
;;
Expand Down
2 changes: 2 additions & 0 deletions src/Psalm/Type/Union.php
Expand Up @@ -4,6 +4,7 @@

use Psalm\Internal\DataFlow\DataFlowNode;
use Psalm\Internal\TypeVisitor\FromDocblockSetter;
use Psalm\Storage\ImmutableNonCloneableTrait;
use Psalm\Type\Atomic\TClassString;
use Psalm\Type\Atomic\TLiteralFloat;
use Psalm\Type\Atomic\TLiteralInt;
Expand Down Expand Up @@ -40,6 +41,7 @@
*/
final class Union implements TypeNode, Stringable
{
use ImmutableNonCloneableTrait;
use UnionTrait;

/**
Expand Down