Skip to content

Commit c4be36a

Browse files
limingxinleodeminy
andauthored
Fixed bug that generate proxy class failed caused by variadic parameters with type. (#4096)
Co-authored-by: Demin Yin <[email protected]>
1 parent 1b334e1 commit c4be36a

File tree

3 files changed

+71
-4
lines changed

3 files changed

+71
-4
lines changed

src/Aop/ProxyCallVisitor.php

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ private function rewriteMethod(ClassMethod $node): ClassMethod
186186
if ($param instanceof Node\Param && $param->variadic) {
187187
$newParam = clone $param;
188188
$newParam->variadic = false;
189+
$newParam->type = null;
189190
$params[$key] = $newParam;
190191
}
191192
}

tests/AstTest.php

+42-3
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ public function testMagicMethods()
119119
$aspect = BarAspect::class;
120120

121121
AspectCollector::setAround($aspect, [
122-
Bar4::class . '::toRewriteMethodString',
122+
Bar4::class . '::toRewriteMethodString1',
123+
Bar4::class . '::toRewriteMethodString2',
124+
Bar4::class . '::toRewriteMethodString3',
125+
Bar4::class . '::toRewriteMethodString4',
123126
], []);
124127

125128
$ast = new Ast();
@@ -139,11 +142,47 @@ public function toMethodString() : string
139142
{
140143
return __METHOD__;
141144
}
142-
public function toRewriteMethodString() : string
145+
/**
146+
* To test method parameters (with type declaration in use).
147+
*/
148+
public function toRewriteMethodString1(int $count) : string
143149
{
144150
$__function__ = __FUNCTION__;
145151
$__method__ = __METHOD__;
146-
return self::__proxyCall(__CLASS__, __FUNCTION__, self::__getParamsMap(__CLASS__, __FUNCTION__, func_get_args()), function () use($__function__, $__method__) {
152+
return self::__proxyCall(__CLASS__, __FUNCTION__, self::__getParamsMap(__CLASS__, __FUNCTION__, func_get_args()), function (int $count) use($__function__, $__method__) {
153+
return $__method__;
154+
});
155+
}
156+
/**
157+
* To test passing by references.
158+
*/
159+
public function toRewriteMethodString2(int &$count) : string
160+
{
161+
$__function__ = __FUNCTION__;
162+
$__method__ = __METHOD__;
163+
return self::__proxyCall(__CLASS__, __FUNCTION__, self::__getParamsMap(__CLASS__, __FUNCTION__, func_get_args()), function (int &$count) use($__function__, $__method__) {
164+
return $__method__;
165+
});
166+
}
167+
/**
168+
* To test variadic parameters (without type declaration).
169+
*/
170+
public function toRewriteMethodString3(...$params) : string
171+
{
172+
$__function__ = __FUNCTION__;
173+
$__method__ = __METHOD__;
174+
return self::__proxyCall(__CLASS__, __FUNCTION__, self::__getParamsMap(__CLASS__, __FUNCTION__, func_get_args()), function ($params) use($__function__, $__method__) {
175+
return $__method__;
176+
});
177+
}
178+
/**
179+
* To test variadic parameters with type declaration.
180+
*/
181+
public function toRewriteMethodString4(int &$count, string ...$params) : string
182+
{
183+
$__function__ = __FUNCTION__;
184+
$__method__ = __METHOD__;
185+
return self::__proxyCall(__CLASS__, __FUNCTION__, self::__getParamsMap(__CLASS__, __FUNCTION__, func_get_args()), function (int &$count, $params) use($__function__, $__method__) {
147186
return $__method__;
148187
});
149188
}

tests/Stub/Ast/Bar4.php

+28-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,34 @@ public function toMethodString(): string
1818
return __METHOD__;
1919
}
2020

21-
public function toRewriteMethodString(): string
21+
/**
22+
* To test method parameters (with type declaration in use).
23+
*/
24+
public function toRewriteMethodString1(int $count): string
25+
{
26+
return __METHOD__;
27+
}
28+
29+
/**
30+
* To test passing by references.
31+
*/
32+
public function toRewriteMethodString2(int &$count): string
33+
{
34+
return __METHOD__;
35+
}
36+
37+
/**
38+
* To test variadic parameters (without type declaration).
39+
*/
40+
public function toRewriteMethodString3(...$params): string
41+
{
42+
return __METHOD__;
43+
}
44+
45+
/**
46+
* To test variadic parameters with type declaration.
47+
*/
48+
public function toRewriteMethodString4(int &$count, string ...$params): string
2249
{
2350
return __METHOD__;
2451
}

0 commit comments

Comments
 (0)