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/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/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..121bbea 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: @@ -128,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 @@ +