Open orchestr7 opened 2 years ago
What if there are several overloads of function foo
with the same number of arguments but different types? Then type of the lambda would be ambiguous. I guess it would make sense for named arguments, because I can't imagine a case, when its type cannot be inferred correctly.
I guess it would make sense for named arguments
I meant only unnamed arguments
I meant some weird corner cases like
fun <T> foo(f: (a: T, b: String) -> Unit) = Unit
fun bar() {
foo { _: Int, s -> println(s) }
}
Here removing : Int
will cause compilation failure
To give another example on built-in stdlib functions,
list.fold(null) { _: Any?, _ -> }
will not type-check if _: Any?
is replaced by _
.
Hm, yes, that's true @petertrr @ephemient. But we need to cover at least simple cases somehow...
Without full type inference it is not possible to determine whether removing the explicit type keeps the same behavior of code or not.
This is a great stylistic bug, that is not handled by IDEA:
diktat should detect and remove a type of such anonymous arguments (
_: Int
)This should also be added to the code style