From 2ed24477925295546ec5cd0a2f388b53687fce94 Mon Sep 17 00:00:00 2001 From: Kirill Nesmeyanov Date: Wed, 10 Apr 2024 21:37:20 +0300 Subject: [PATCH] Complete language table --- Writerside/topics/language.md | 519 ++++++++++++++++++- Writerside/topics/language/callable-types.md | 6 +- 2 files changed, 494 insertions(+), 31 deletions(-) diff --git a/Writerside/topics/language.md b/Writerside/topics/language.md index 68ee8e6..a30a8a1 100644 --- a/Writerside/topics/language.md +++ b/Writerside/topics/language.md @@ -37,27 +37,27 @@ General table across all type parsing capabilities - 32/32 + 56/56 - 19/32 + 39/56 - 25/32 + 43/56 - ?/32 + ?/56 - ?/32 + ?/56 @@ -1511,26 +1511,489 @@ Below is a list of grammar of shaped types. Below is a list of grammar of callable (function) types. -This table is not yet formatted - -| Code Example | TypeLang | Psalm | PHPStan | -|-----------------------------------------------------------------------|-------------------|----------------------------------------------------|------------| -| Simple Func `callable()` | ✔️ | ✔️ | ✔️ | -| Typed Func `callable(): mixed` | ✔️ | ✔️ | ✔️ | -| Func Args `callable(T)` | ✔️ | ✔️ | ✔️ | -| Optional Arg `callable(T=)` | ✔️ | ✔️ | ✔️ | -| Named Arg `callable(T $name)` | ✔️ | ✔️ | ✔️ | -| Optional Named Arg `callable(T $name=)` | ✔️ | [❌ Internal Error](https://psalm.dev/r/9ae58ed797) | ✔️ | -| Suffixed Variadic Arg `callable(T...)` | ✔️ | ✔️ | ✔️ | -| Prefixed Variadic Arg `callable(...T)` | ✔️ | ✔️ | ✔️ | -| Prefixed + Suffixed Variadic Named Arg `callable(...T ...$name)` | ✔️ Syntax Error | [❌ Internal Error](https://psalm.dev/r/4a6476fff6) | ❌ No Error | -| Optional Variadic Arg `callable(...T=)` | ✔️ Semantic Error | ✔️ Semantic Error | ❌ No Error | -| Suffixed Variadic Named Arg `callable(T ...$arg)` | ✔️ | ✔️ | ✔️ | -| Prefixed Variadic Named Arg `callable(...T $arg)` | ✔️ | [❌ Internal Error](https://psalm.dev/r/2dac434b3f) | ✔️ | -| Reference Arg `callable(T&)` | ✔️ | [❌ Not Supported](https://psalm.dev/r/bb604c4219) | ✔️ | -| Optional Reference Arg `callable(T&=)` | ✔️ | [❌ Not Supported](https://psalm.dev/r/fc3041a846) | ✔️ | -| Optional Reference Named Arg `callable(T &$name=)` | ✔️ | [❌ Not Supported](https://psalm.dev/r/14dcf8634f) | ✔️ | -| Reference Named Variadic Arg `callable(T &...$name)` | ✔️ | [❌ Not Supported](https://psalm.dev/r/7a64356034) | ✔️ | -| Reference Named Prefix Variadic Arg `callable(...T &$name)` | ✔️ | [❌ Not Supported](https://psalm.dev/r/bf7dcbc9b4) | ✔️ | -| Optional Reference Named Variadic Arg `callable(T &...$name=)` | ✔️ Semantic Error | ✔️ Semantic Error | ❌ No Error | -| Optional Reference Named Prefix Variadic Arg `callable(...T &$name=)` | ✔️ Semantic Error | ✔️ Semantic Error | ❌ No Error | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+  TypeLang + +  Psalm + +  PHPStan + +  PHAN + +  phpDocumentor +
+ + Non-typed callable types + + + callable() + +
+ + + Not Supported + +
+ + Typed callable types + + + callable(): Type + +
+ + Callable with typed parameters + + + callable(Type): T + +
+ + Callable with optional parameters + + + callable(Type=): T + +
+ + Callable with named parameters + + + callable(Type $name): T + +
+ + Callable with optional named parameters + + + callable(Type $name=): T + +
+ + + Not Supported + +
+ + Callable with output parameters + + + callable(T&): T + +
Works with restrictions 1
+ + + + // OK + callable(T&): U + + + // Bug: Intersection types must be all objects, + // Psalm\Type\Atomic\TInt provided in docblock + callable(int&): U + + Open in psalm.dev + + +
+ + Callable with output optional parameters + + + callable(T&=): T + +
Works with restrictions 1
+ + + + // OK + callable(T&=): U + + + // Bug: Intersection types must be all objects, + // Psalm\Type\Atomic\TInt provided in docblock + callable(int&=): U + + Open in psalm.dev + + +
+ + Callable with output optional named parameters + + + callable(T &$name=): T + +
+ + + Not Supported + +
+ + Callable with suffixed variadic parameters + + + callable(Type...): T + +
+ + Callable with prefixed variadic parameters + + + callable(...Type): T + +
+ + + Not Supported + +
+ + Callable with prefixed and suffixed variadic parameters + + + callable(...Type ...$name): T + +
Works with restrictions 1 Works with restrictions 2
+ + This expression is incorrect because the "variadic" + lexeme ... must be present in the parameter + in a single copy. The parser must throw a syntax or + semantic error. + + + + + callable(...int ...$name) + // Internal Psalm error on line ...: + // Unrecognised parse tree type Psalm\Internal\Type\ParseTree\CallableParamTree + + Open in psalm.dev + + + + callable(...int ...$name) + // PHPDoc tag @return has invalid value (callable(...int ...$name): T): + // Unexpected token "(", expected TOKEN_HORIZONTAL_WS at ... + + Open in phpstan.org + + +
+ + Callable with optional variadic parameters + + + callable(Type...=): T + callable(...Type=): T + +
Works with restrictions 1 + + + No Error + +
+ + This expression is incorrect because any variadic + parameter is already optional. The parser must + throw a syntax or semantic error. + + + + + // OK: Cannot have variadic param with a default in docblock + callable(...T=): T + + + // Bug: Cannot have duplicate tokens in docblock + callable(T...=): T + + Open in psalm.dev + + +
+ + Callable with named variadic parameters + + + callable(Type ...$name): T + callable(...Type $name): T + +
Works with restrictions 1 Works with restrictions 2
+ + + + callable(...Type $name): T + // Internal Psalm error on line ...: + // Unrecognised parse tree type Psalm\Internal\Type\ParseTree\CallableParamTree + + Open in psalm.dev + + + + callable(...Type $name): T + // PHPDoc tag @return has invalid value (callable(...Type $name): T): + // Unexpected token "(", expected TOKEN_HORIZONTAL_WS at ... + + Open in phpstan.org + + +
+ + Callable with output named variadic parameters + + + callable(Type &...$name): T + callable(...Type &$name): T + +
Works with restrictions 1 Works with restrictions 2
+ + + + // OK + callable(T &...$name): U + + + // Bug: Intersection types must be all objects, + // Psalm\Type\Atomic\TInt provided in docblock + callable(int &...$name): U + + Open in psalm.dev + + + + callable(...Type &$name): T + // PHPDoc tag @return has invalid value (callable(...Type &$name): T): + // Unexpected token "(", expected TOKEN_HORIZONTAL_WS at ... + + Open in phpstan.org + + +
+ + 15/15 + + + + 13/15 + + + + 12/15 + + + + ?/15 + + + + ?/10 + +
diff --git a/Writerside/topics/language/callable-types.md b/Writerside/topics/language/callable-types.md index 0b14ca2..c77b6d3 100644 --- a/Writerside/topics/language/callable-types.md +++ b/Writerside/topics/language/callable-types.md @@ -61,7 +61,7 @@ Just like in the PHP language. -### References +### Output Parameters Passing a parameter by reference means that the function can change the passed variable while it is running. @@ -98,7 +98,7 @@ the type and before the name. -### Optional +### Optional Parameters An optional parameter means that the argument may not be passed when such a function is called. @@ -147,7 +147,7 @@ parameter description. -### Variadic +### Variadic Parameters Variadic parameters are indicated by the "`...`" and can be placed either _before the type_ or _before the parameter name._