Skip to content

Commit 46320dc

Browse files
committed
Fix class detail parsing for function types
1 parent 0d7259e commit 46320dc

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ XP Framework Core ChangeLog
77

88
### Bugfixes
99

10+
* Fixed class detail parsing for function types
11+
(@thekid)
1012
* Fixed Type::forName() to also work for the `callable` type union.
1113
(@thekid)
1214
* Fixed issue #74: Ambiguity in function types

src/main/php/lang/reflect/ClassParser.class.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,12 @@ public static function typeIn($text) {
322322
$p= self::matching($text, '(', ')');
323323
$p+= strspn($text, ': ', $p);
324324
return substr($text, 0, $p).self::typeIn(substr($text, $p));
325+
} else if (0 === strncmp($text, '(function(', 10)) {
326+
$p= self::matching($text, '(', ')');
327+
return substr($text, 0, $p).self::typeIn(substr($text, $p));
328+
} else if ('[' === $text{0}) {
329+
$p= self::matching($text, '[', ']');
330+
return substr($text, 0, $p);
325331
} else if (strstr($text, '<')) {
326332
$p= self::matching($text, '<', '>');
327333
return substr($text, 0, $p);

src/main/resources/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6.2.3-dev
1+
6.2.2

src/test/php/net/xp_framework/unittest/reflection/ClassDetailsTest.class.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,30 @@ public function function_returning_generic() {
134134
$this->assertEquals('function(): util.Filter<string>', $details[DETAIL_ARGUMENTS][0]);
135135
}
136136

137+
#[@test]
138+
public function function_returning_array() {
139+
$details= $this->parseComment('/** @param function(): int[] param1 */');
140+
$this->assertEquals('function(): int[]', $details[DETAIL_ARGUMENTS][0]);
141+
}
142+
143+
#[@test]
144+
public function array_of_functions() {
145+
$details= $this->parseComment('/** @param (function(): int)[] param1 */');
146+
$this->assertEquals('(function(): int)[]', $details[DETAIL_ARGUMENTS][0]);
147+
}
148+
149+
#[@test]
150+
public function map_of_functions() {
151+
$details= $this->parseComment('/** @param [:function(): int] param1 */');
152+
$this->assertEquals('[:function(): int]', $details[DETAIL_ARGUMENTS][0]);
153+
}
154+
155+
#[@test]
156+
public function map_of_functions_with_braces() {
157+
$details= $this->parseComment('/** @param [:(function(): int)] param1 */');
158+
$this->assertEquals('[:(function(): int)]', $details[DETAIL_ARGUMENTS][0]);
159+
}
160+
137161
#[@test]
138162
public function throwsList() {
139163
$details= $this->parseComment('

0 commit comments

Comments
 (0)