-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Named parameters and ParamArray do not not play nice together #597
Comments
Isn't it always has been like this ? |
Confirming what @RevensofT is saying, that arguments passed into Example("abcd", i:=5)
Function Example(i As Integer, ParamArray p As String()) As Boolean
Return False
End Function |
@zspitz : yes, they have to be last, that is what I meant by not playing nicely together. The reason why ParmaArrays have to be last is that there is no other way of deciding when the parameters end UNLESS named arguments are used, in which case, all named arguments could be removed from consideration. Before named parameters, given a call to fn(integer, paramarray integer, integer, integer) it would have been impossible to determine whether fn(1,2,3) was supposed to represent fn(1, {}, 2,3) with an empty parameter array, or whether it was supposed to represent fn(1, { 2}, 3) where the last parameter was left off by mistake, or even fn(1, { 2,3}) and the last 2 were left off by mistake , with named parameters, the paramarray still needs to be declared last, eg sub fn(first as integer, second as integer, third as integer, paramarray i() as integer), but calling it as fn(4,5,6,third:=3, second:=2, first:=1) is no longer ambiguous. With named parameters, paramarray parameters should be more flexible. |
Correct me if I'm wrong (only verified with a quick LINQPad check), but I think that the rule is that any unnamed parameters still need to be in order. For example, if the first parameter in the call is unnamed, it needs to be the actual first parameter. If you use a named version of the first parameter later, it's marked as an error because you're assigning the same parameter twice, and this behavior is not exclusive to methods with ParamArray. |
@gilfusion : you can’t use a named parameter with param array. which has all of elements in the correct order with the correct types, will fail, because you can’t use a named parameter with paramarray. |
@jrmoreno1 interestingly, Visual Studio does not warn you of this construct, leaving it to the VB compiler to complain you're doing it wrong |
@Halofreak1990 : c# allows you to use named parameters and even reorder them, but isn’t smart enough to figure out that it can determine that the remaining items must be part of the params , by eliminating the other parameters. |
I'm creating an extension method with 3 parameters, the last being a paramaray. When attempting to reorder the parameters using named parameters, the signature is unable to be matched.
This gets two errors, BC30512 and BC36584.
The text was updated successfully, but these errors were encountered: