infix fun doSomething(string: String) {}
fun example() {
doSomething "" //compile error
doSomething("") //allowed, but without infix syntax
this doSomething "" //allowed, but the "this" should be innecesary
}
}
Shouldn’t the first case be accepted by the compiler?
For any other function, if you are inside a class you don’t need to use this keyword,
the same happens with extension functions and lambdas.
I guess it has to do with the way infix functions work.
Infix only works with exactly one argument (or 2 if you count the receiver) so the function name can be placed between the 2 arguments.
IMO removing the first argument looks strange and it is not really intuitive to understand. The normal infix case is easy to understand as we are used to it from normal operators. And adding additional “operators” and similar functions is what I feel infix should be used for.
An infix function always requires the left-hand and the right-hand side arguments. Making it possible to omit one would lead to numerous ambiguities in parsing.
It is, but it doesn’t matter. The syntax of an infix expression does not allow the left hand side operand to be omitted, even if it can be omitted in other contexts.