Repository navigation
parser: pass default values for omitted optional arguments - #21
Merged
Merged
Conversation
When the parameter types did not decide between two overloads, the method resolver preferred the one with more parameters, as the reflection binder does. As a result, 'M(1)' selected M(int, int = 0) instead of M(int), and overloads that both need default arguments, such as M(int, int = 0) and M(int, int = 0, int = 0), were not reported as ambiguous. Prefer the overload whose parameters all get arguments, as C# does, and report overloads that both need default arguments as ambiguous. When both overloads are applicable only in their expanded form, the one with more declared parameters still wins.
A call that omitted optional arguments or passed no arguments for a
parameter array failed with "Incorrect number of arguments supplied
for call to method", although the method resolver had accepted it.
For example, 'string.Format("x")', '"a,b".Split(",")', and
'"a,b".Split(',')' failed this way.
Pass an empty array for a parameter array without arguments and the
default value for an omitted optional parameter, as C# does. A
parameter declared with [Optional] and without a default value gets
Type.Missing if its type is object, and the default value of its type
otherwise.
rameel
force-pushed
the
parser/optional-arguments
branch
from
November 18, 2026 08:18
d503313 to
565ae48
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A call that omitted optional arguments or passed no arguments for a
paramsparameter failed withIncorrect number of arguments supplied for call to method, although the method resolver had accepted it. For example,string.Format("x"),"a,b".Split(","), and"a,b".Split(',')failed this way.This PR passes an empty array for a parameter array without arguments and the default value for an omitted optional parameter, as C# does. A parameter declared with
[Optional]and without a default value getsType.Missingif its type isobject, and the default value of its type otherwise.The method resolver also chose between such overloads differently from C#: it preferred the overload with more parameters, so
M(1)would callM(int, int = 0)instead ofM(int). It now prefers the overload whose parameters all get arguments and reports overloads that both need default arguments, such asM(int, int = 0)andM(int, int = 0, int = 0), as ambiguous.