Puzzler that crushed my production


#1
private fun foo(one: (String) -> Unit = {}, two: (String) -> Unit = {}) {
    one("one")
    two("two")
}

fun main(args: Array<String>) {
    foo({ print(it) })
    foo { print(it) } 
}

I think should be inspection about it.


#2

But I can’t realize in in which case…


#3
Facts to solve
  • When the last parameter is a lambda, it can be passed in curly brackets.
  • Function parameters will be implemented from the beginning (arguments can only be skipped when they are named).

If there needs to be an inspection, I think the case is:

  • The method:

    1. The method has at least two optional lambda’s
    2. The methods last parameter is an optional lambda.
  • The function call:

    1. The function call has as last argument an unnamed lambda.
    2. The called method has on the n’th place an optional lamda, where n is the count of arguments.

#4

You should file an issue with this example to http://kotl.in/issue anyway