thanks @arocnies, as you say, my question was sufficiently unclear that @lamba92 had understandably misinterpreted the question.
However, you clearly nailed exactly what I was raising.
Agree that the Fred().invoke{
syntax could be the clearest available at this time.
The main use case is when creating a literal object enabling DSL like features within the current context. As the DSL lingusitics of ‘Fred’ are requires within the lambda block supplied to the Fred class, there is not normally a use for storing the Fred object in a var, and this interupts the DSL nature of the syntax.
While I agree the explicit .invoke is the best available, in the spirit of DSLs, given that the syntax of
Fred() { // lambda supplied to invoke method of object instanced by Fred()
}
fits within the syntax rules of kotlin, why adjust the compiler so there is no attempt to provide the lambda as an argument to the constructor of Fred, in the situation where no constructor for Fred accepts lambda parameters?
Is there a problem with allowing this that you can see?