Skip to content

Commit 909a3ed

Browse files
committed
Fix non-generic and untyped parameters not being taken into account
1 parent ec6c202 commit 909a3ed

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ XP generics for PHP - ChangeLog
33

44
## ?.?.? / ????-??-??
55

6+
## 2.0.1 / 2024-08-03
7+
8+
* Fixed non-generic and untyped parameters not being taken into account
9+
(@thekid)
10+
611
## 2.0.0 / 2024-03-24
712

813
* Dropped support for PHP 7.0 - 7.3 - @thekid

src/main/php/lang/ast/syntax/php/Generics.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ public static function method($method, $components) {
134134
if ($parameter->type && ($generic= self::generic($parameter->type, $components))) {
135135
$params[]= $generic.($parameter->variadic ? '...' : '');
136136
$parameter->type= null;
137+
} else {
138+
$params[]= '';
137139
}
138140
}
139141
$params && $r[]= [new Literal("'params'"), new Literal("'".implode(', ', $params)."'")];

src/test/php/lang/ast/syntax/php/unittest/MethodsTest.class.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class MethodsTest extends EmittingTest {
2424
* @param string $method
2525
* @return lang.Type
2626
*/
27-
private function parameterType($type, $method) {
28-
return Reflection::type($type)->method($method)->parameter(0)->constraint()->type();
27+
private function parameterType($type, $method, $position= 0) {
28+
return Reflection::type($type)->method($method)->parameter($position)->constraint()->type();
2929
}
3030

3131
/**
@@ -49,6 +49,16 @@ public function push(E $element) { }
4949
Assert::equals($c, $this->parameterType($t->newGenericType([$c]), 'push'));
5050
}
5151

52+
#[Test]
53+
public function generic_parameter_type_following_non_generic() {
54+
$t= $this->type('class %T<E> {
55+
public function map(string $name, E $element) { }
56+
}');
57+
58+
$c= typeof($this);
59+
Assert::equals($c, $this->parameterType($t->newGenericType([$c]), 'map', 1));
60+
}
61+
5262
#[Test]
5363
public function generic_type_union() {
5464
$t= $this->type('class %T<E> {

0 commit comments

Comments
 (0)