Skip to content

Commit 4446bc8

Browse files
committed
Kotlin 1.4: non-spread named arguments for varargs
1 parent 518aee7 commit 4446bc8

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

docs/src/md/kotlin.core/declarations.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,11 @@ If one wants to mix named and positional arguments, the argument list must confo
451451

452452
> Note: in Kotlin version 1.3 and earlier, $PoN_i$ were restricted to positional arguments only.
453453
454+
If one needs to provide a named argument to a [variable length parameter][Variable length parameters], it can be achieved via either regular named argument `arg = arr` or a spread operator expression form `arg = *arr`.
455+
In both cases type of `arr` must be a subtype of [$\ATS(\Array(\outV T))$][Array types] for a variable length parameter of type $T$.
456+
457+
> Note: in Kotlin version 1.3 and earlier, only the spread operator expression form for named variable length arguments was supported.
458+
454459
Kotlin also supports *default* parameters --- parameters which have a default value used in function invocation, if the corresponding argument is missing. Note that default parameters cannot be used to provide a value for positional argument *in the middle* of the positional argument list; allowing this would create an ambiguity of which argument for position $i$ is the correct one: explicit one provided by the developer or implicit one from the default value.
455460

456461
```kotlin
@@ -483,7 +488,7 @@ One of the parameters may be designated as being variable length (aka *vararg*).
483488
A parameter list $(p_1, \ldots, \text{vararg }p_i: P_i = v_i, \ldots, p_n)$ means a function may be called with any number of arguments in the i-th position.
484489
These arguments are represented inside function body $b$ as a value $p_i$ of type, which is the result of [*array type specialization*][Array types] of type $\Array(\outV P_i)$.
485490

486-
> Important: we also consider variable length parameters to have such types for the purposes of type inference.
491+
> Important: we also consider variable length parameters to have such types for the purposes of type inference and named parameters.
487492
> TODO(Something else?)
488493
489494
If a variable length parameter is not last in the parameter list, all subsequent arguments in the function invocation should be specified as named arguments.

docs/src/md/kotlin.core/expressions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -977,11 +977,11 @@ As described in [the function declaration section][Function declaration], functi
977977
978978
- Explicit receiver argument, used in calls with explicit receivers;
979979
- Normal arguments, provided directly inside the parentheses part of the call;
980-
- Named arguments in the form `identifier = value`, where `identifier` is a parameter name used at declaration-site of the function;
980+
- [Named arguments][Named, positional and default parameters] in the form `identifier = value`, where `identifier` is a parameter name used at declaration-site of the function;
981981
- [Variable length arguments][Variable length parameters], provided the same way as normal arguments;
982982
- A trailing lambda literal argument, specified outside the parentheses (see [lambda literal section][Lambda literals] for details).
983983
984-
In addition to these, a function declaration may specify a number of default parameters, which allow one to omit specifying them at call-site, in which case their default value is used during the evaluation.
984+
In addition to these, a function declaration may specify a number of [default parameters][Named, positional and default parameters], which allow one to omit specifying them at call-site, in which case their default value is used during the evaluation.
985985
986986
The evaluation of a function call begins with the evaluation of its explicit receiver, if it is present.
987987
Function arguments are then evaluated **in the order of their appearance in the function call** left-to-right, with no consideration on how the parameters of the function were specified during function declaration.
@@ -1041,7 +1041,7 @@ It is allowed to mix spread arguments with regular arguments, all fitting into t
10411041
Spread operator expressions are not allowed in any other context.
10421042
See [Variable length parameter][Variable length parameters] section for details.
10431043
1044-
The type of a spread argument must be a subtype of [$\ATS(T)$][Array types] for a variable length parameter of type $T$.
1044+
The type of a spread argument must be a subtype of [$\ATS(\Array(\outV T))$][Array types] for a variable length parameter of type $T$.
10451045
10461046
> Example: for parameter `vararg a: Int` the type of a corresponding spread argument must be a subtype of `IntArray`, for parameter `vararg b: T` where `T` is a classifier type the type of a corresponding spread argument must be a subtype of `Array<out T>`.
10471047

docs/src/md/kotlin.core/type-system.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ However, they are **not** related by subtyping; meaning one cannot pass a `Boole
205205
206206
> Note: specialized and non-specialized array types match modulo their iterator types, which are also specialized; `Iterator<Int>` is specialized to `IntIterator`.
207207
208-
*Array type specialization* $\ATS(T)$ is a transformation of a generic $\Array(T)$ type to a corresponding specialized version, which works as follows.
208+
*Array type specialization* $\ATS(A)$ is a transformation of a generic $\Array(T)$ type to a corresponding specialized version, which works as follows.
209209

210210
* if $\Array(T)$ has a specialized version `TArray`, $\ATS(\Array(T)) = \texttt{TArray}$
211211
* if $\Array(T)$ does not have a specialized version, $\ATS(\Array(T)) = \Array(T)$

0 commit comments

Comments
 (0)