Skip to content

parser: pass an array argument as the parameter array - #20

Merged
rameel merged 2 commits into
mainfrom
parser/param-array-argument
Nov 17, 2026
Merged

rameel merged 2 commits into
mainfrom
parser/param-array-argument

Conversation

@rameel

@rameel rameel commented Nov 17, 2026

Copy link
Copy Markdown
Owner

A call with a params parameter always wrapped its arguments in a new array, even when the method resolver had selected the normal form because an array was passed directly. As a result, string.Join(",", words) with a string[] failed with No coercion operator is defined between types 'System.String[]' and 'System.String', and a string[] passed to params object[] became the only element of a new array.

This PR passes the only argument for the parameter array as the array itself when it converts to the array type, as C# does. An int[] passed to params object[] still becomes a single element, as in C#.

The + operator merged the operands of a nested string.Concat call and took its only argument for an array created for the expanded form. It now merges only such arrays and keeps other single-argument calls as one operand, so string.Concat(objects) + "!" concatenates the elements of the array, and string.Concat("x") + "y" no longer fails with InvalidCastException.

When the '+' operator merged the operands of a nested string.Concat
call, it took the only argument of the call for the array created for
the expanded form. Another overload with one argument failed with
InvalidCastException: for example, 'string.Concat("x") + "y"' calls
Concat(object).

Merge only the elements of an array created for the expanded form, and
keep other single-argument calls as one operand.
The arguments for a params parameter were always wrapped in a new
array, even when the call was resolved in its normal form with an
array passed directly. As a result, 'string.Join(",", words)' with a
string[] failed with "No coercion operator is defined between types
'System.String[]' and 'System.String'", and a string[] passed to
'params object[]' became the only element of a new array.

Pass the only argument for the parameter array as the array itself
when it converts to the array type, as C# does. In other cases the
arguments are still wrapped in an array.
@rameel
rameel merged commit 9bbb10c into main Nov 17, 2026
1 check passed
@rameel
rameel deleted the parser/param-array-argument branch November 17, 2026 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant