This is because Kotlin doesn’t require semicolons for ending statements, so it has to “guess” where statements are ending. Your last example is interpreted like
val assertion: AlchemyAssertion<Account> = AlchemyAssertion;
{
}
and thus doesn’t work. I’d recommend to always put the “{” on the same line.
I’m with you. Hiding braces on the end of the line is an abomination and have no idea how anyone ever thought this was a good idea. This crops up in other cases as well, such as higher order functions that have a single parameter that is a function and the ability to drop the parentheses.
value.apply
{
doSomething()
}
does not compile, but does if you hide the opening brace on the end of the line. I have taken to doing this instead, but then you get a warning about unnecessary parentheses:
value.apply()
{
doSomething()
}
So unlike Jonathan, I do not recommend you make your code harder to read to work around the fact that the compiler is broken, I want to see the compiler quit advocating the less readable style.
Can you tell that I this is a hot button issue with me?