From c89822d16c14af3f7331ea30cf3ff11fa7d68df8 Mon Sep 17 00:00:00 2001 From: Anton Sukhachev Date: Mon, 1 Apr 2024 22:01:14 +0300 Subject: [PATCH 1/2] nikic/PHP-Parser v5.0.2 --- .github/workflows/tests.yml | 2 +- composer.json | 2 +- src/Compiler/Parser.php | 10 ++++------ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 01de7dd..6fecc3c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,7 +22,7 @@ jobs: steps: - name: "Checkout" - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" - name: "Install PHP" uses: "shivammathur/setup-php@v2" diff --git a/composer.json b/composer.json index 936d040..f561bb2 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "require": { "php": ">=7.4", "composer-plugin-api": "^1.0|^2.0", - "mrsuh/php-parser": "94.18.0", + "mrsuh/php-parser": "95.0.2", "symfony/console": "^4.0|^5.0|^6.0", "symfony/filesystem": "^4.0|^5.0|^6.0", "symfony/finder": "^4.0|^5.0|^6.0" diff --git a/src/Compiler/Parser.php b/src/Compiler/Parser.php index 8cf887e..27c0322 100644 --- a/src/Compiler/Parser.php +++ b/src/Compiler/Parser.php @@ -3,7 +3,6 @@ namespace Mrsuh\PhpGenerics\Compiler; use Mrsuh\PhpGenerics\Compiler\ClassFinder\ClassFinderInterface; -use PhpParser\Lexer\Emulative; use PhpParser\Node; use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Expr\Instanceof_; @@ -23,10 +22,9 @@ class Parser { public static function parse(string $code): array { - $lexer = new Emulative(); - $parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7, $lexer); - - return $parser->parse($code); + return (new ParserFactory) + ->createForNewestSupportedVersion() + ->parse($code); } /** @@ -114,7 +112,7 @@ public static function setNodeName(Node &$node, string $type): void if (self::isBuiltinType($type)) { $node = new Node\Identifier($type); } else { - $node->parts = explode('\\', $type); + $node->name = $type; } break; case $node instanceof Node\Identifier: From 5ab38b354ee52f985e5d6e2bfcb772ff1d23936b Mon Sep 17 00:00:00 2001 From: Anton Sukhachev Date: Sun, 7 Apr 2024 08:48:20 +0300 Subject: [PATCH 2/2] nikic/PHP-Parser v5.0.2 --- bin/test.php | 3 ++- src/Compiler/Parser.php | 8 +++++++- .../230-builtin-types/input/Command/Usage.php | 12 ++++++++++++ .../230-builtin-types/input/Entity/Bird.php | 8 ++++++++ .../230-builtin-types/input/Entity/Cat.php | 8 ++++++++ .../230-builtin-types/input/Generic/Box.php | 13 +++++++++++++ .../230-builtin-types/input/Generic/Container.php | 12 ++++++++++++ .../230-builtin-types/output/Command/Usage.php | 10 ++++++++++ ...everAndTrueAndTestEntityBirdAndTestEntityCat.php | 13 +++++++++++++ ...everAndTrueAndTestEntityBirdAndTestEntityCat.php | 11 +++++++++++ 10 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 tests/monomorphic/230-builtin-types/input/Command/Usage.php create mode 100644 tests/monomorphic/230-builtin-types/input/Entity/Bird.php create mode 100644 tests/monomorphic/230-builtin-types/input/Entity/Cat.php create mode 100644 tests/monomorphic/230-builtin-types/input/Generic/Box.php create mode 100644 tests/monomorphic/230-builtin-types/input/Generic/Container.php create mode 100644 tests/monomorphic/230-builtin-types/output/Command/Usage.php create mode 100644 tests/monomorphic/230-builtin-types/output/Generic/BoxForArrayAndCallableAndBoolAndIntAndFloatAndStringAndNullAndVoidAndObjectAndFalseAndMixedAndNeverAndTrueAndTestEntityBirdAndTestEntityCat.php create mode 100644 tests/monomorphic/230-builtin-types/output/Generic/ContainerForArrayAndCallableAndBoolAndIntAndFloatAndStringAndNullAndVoidAndObjectAndFalseAndMixedAndNeverAndTrueAndTestEntityBirdAndTestEntityCat.php diff --git a/bin/test.php b/bin/test.php index 3a739fb..1663090 100644 --- a/bin/test.php +++ b/bin/test.php @@ -70,7 +70,8 @@ } if ($outputFiles->count() !== count($result->getConcreteClasses())) { - $success = false; + $allTestsSuccess = false; + printf("%s - [skip failed]\n", $directory->getBasename()); continue; } diff --git a/src/Compiler/Parser.php b/src/Compiler/Parser.php index 27c0322..121bbea 100644 --- a/src/Compiler/Parser.php +++ b/src/Compiler/Parser.php @@ -126,14 +126,20 @@ public static function setNodeName(Node &$node, string $type): void public static function isBuiltinType(string $type): bool { $builtinTypes = [ + 'array' => true, + 'callable' => true, 'bool' => true, 'int' => true, 'float' => true, 'string' => true, 'iterable' => true, + 'void' => true, 'object' => true, + 'null' => true, + 'false' => true, 'mixed' => true, - 'array' => true, + 'never' => true, + 'true' => true, ]; return isset($builtinTypes[strtolower($type)]); diff --git a/tests/monomorphic/230-builtin-types/input/Command/Usage.php b/tests/monomorphic/230-builtin-types/input/Command/Usage.php new file mode 100644 index 0000000..7267b04 --- /dev/null +++ b/tests/monomorphic/230-builtin-types/input/Command/Usage.php @@ -0,0 +1,12 @@ + +{ + +} diff --git a/tests/monomorphic/230-builtin-types/input/Entity/Bird.php b/tests/monomorphic/230-builtin-types/input/Entity/Bird.php new file mode 100644 index 0000000..f1f6774 --- /dev/null +++ b/tests/monomorphic/230-builtin-types/input/Entity/Bird.php @@ -0,0 +1,8 @@ + { + + public function test($obj): void { + var_dump(Container::class); + } +} diff --git a/tests/monomorphic/230-builtin-types/input/Generic/Container.php b/tests/monomorphic/230-builtin-types/input/Generic/Container.php new file mode 100644 index 0000000..c9b72a1 --- /dev/null +++ b/tests/monomorphic/230-builtin-types/input/Generic/Container.php @@ -0,0 +1,12 @@ + { + + private readonly A|B|C|D|E|F|G|H|I|G|K|L|M|N|O|P $content = null; + + public function setContent(A|B|C|D|E|F|G|H|I|G|K|L|M|N|O|P $content): A|B|C|D|E|F|G|H|I|G|K|L|M|N|O|P { + + } +} diff --git a/tests/monomorphic/230-builtin-types/output/Command/Usage.php b/tests/monomorphic/230-builtin-types/output/Command/Usage.php new file mode 100644 index 0000000..c921406 --- /dev/null +++ b/tests/monomorphic/230-builtin-types/output/Command/Usage.php @@ -0,0 +1,10 @@ +