Hi, why Kotlin does not allow the use named argume...
# kotlin-native
j
Hi, why Kotlin does not allow the use named arguments for function types?
m
named parameters in function types are not enforced, but rather only used as hints for the IDE for what to name the parameters, and aren't guaranteed. For example, the following would also be valid:
Copy code
fun myFunction(object: Any) {
    // ...
}

// no parameter named `argument`, but it's fine since it matches the type used internally: `(Any) -> Unit`
Test(::myFunction)
j
I know that a named argument is not necessarily used for function use. As you said, omitting the named works just fine. However, I want to know why, although named arguments are allowed for general functions, they are not allowed for functional types.
Copy code
fun test(content: (argument: Any) -> Unit) {
    content(argument = "hi") // disallow
}

fun test2(argument: Any) {
    test2(argument = "hi") // allow
}
h
Because lambdas do not store these metadata and requires ordered parameters.
👍 2
Although relaxing this rule in the same module should be nice
j
huh thank you! I understand perfectly. 👍