Skip to content

Commit f545fc3

Browse files
committed
When callable returns callable the return type needs to be put in parentheses
1 parent 178b33a commit f545fc3

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Ast/Type/CallableTypeNode.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ public function __construct(IdentifierTypeNode $identifier, array $parameters, T
2929

3030
public function __toString(): string
3131
{
32+
$returnType = $this->returnType;
33+
if ($returnType instanceof self) {
34+
$returnType = "({$returnType})";
35+
}
3236
$parameters = implode(', ', $this->parameters);
33-
return "{$this->identifier}({$parameters}): {$this->returnType}";
37+
return "{$this->identifier}({$parameters}): {$returnType}";
3438
}
3539

3640
}

tests/PHPStan/Parser/TypeParserTest.php

+16
Original file line numberDiff line numberDiff line change
@@ -1885,6 +1885,22 @@ public function provideParseData(): array
18851885
),
18861886
]),
18871887
],
1888+
[
1889+
'Closure(Foo): (Closure(Foo): Bar)',
1890+
new CallableTypeNode(
1891+
new IdentifierTypeNode('Closure'),
1892+
[
1893+
new CallableTypeParameterNode(new IdentifierTypeNode('Foo'), false, false, '', false),
1894+
],
1895+
new CallableTypeNode(
1896+
new IdentifierTypeNode('Closure'),
1897+
[
1898+
new CallableTypeParameterNode(new IdentifierTypeNode('Foo'), false, false, '', false),
1899+
],
1900+
new IdentifierTypeNode('Bar')
1901+
)
1902+
),
1903+
],
18881904
];
18891905
}
18901906

0 commit comments

Comments
 (0)