Use named argument in error for variadic types#3611
Use named argument in error for variadic types#3611ondrejmirtes merged 1 commit intophpstan:2.0.xfrom
Conversation
|
I can do that, but let's first agree on the error message: -Parameter ...$args of method NamedArgumentsMethod\Foo::doIpsum() expects string, int given.
+Named argument foo for parameter ...$args of method NamedArgumentsMethod\Foo::doIpsum() expects string, int given.? |
|
What about |
|
(Only add "variadic" before parameter only for this specific message, not always.) |
93e808d to
991773b
Compare
|
Updated the PR
Seeing this, I don't think it's what you had in mind. How to deal with this when I need to do this in Introduce a 3rd nullable argument and only set it for |
991773b to
292ee14
Compare
|
No, the point for doing it in The current version is wrong for non-variadic parameters. |
Could you tell me what's wrong? I'm lost now. |
292ee14 to
34570b7
Compare
if (is_int($positionOrNamed)) {
$parts[] = 'Parameter #' . $positionOrNamed;
} elseif (is_string($positionOrNamed)) {
$parts[] = 'Named argument ' . $positionOrNamed . ' for variadic parameter';
} else {
$parts[] = 'Parameter';
}The For example: |
|
Wow, that doesn't make any sense at all indeed. |
When a type is variadic, and multiple named arguments are used, it's often hard to tell for which argument the error is coming. Since we have the named argument, we could use it in this situation.
34570b7 to
e447874
Compare
|
Alright, I think I have it now. |
|
Thank you! |
When a type is variadic, and multiple named arguments are used, it's often hard to tell for which argument the error is coming.
Since we have the named argument, we could use it in this situation.
Example:
Before the error would be:
And one had to inspect the different method calls to see where it might originate.
After:
It's immediately clear it's related to
foonamed argument.