Is there any reason why this works: (implementing a functional interface by delegation)
Copy code
object ColorEncoder : Encoder<Color> by { Encoder { appendable, t -> appendable.appendColor(t) }}()
But inlining the lambda body to this doesnt:
Copy code
object ColorEncoder : Encoder<Color> by Encoder { appendable, t -> appendable.appendColor(t) }
(I get that we can use a val instead, but would like to use objects to keep things consistent)
k
Kroppeb
12/09/2022, 7:58 PM
What if you put it in parentheses?
e
Emil Kantis
12/09/2022, 8:27 PM
Parentheses work.. 👍
Emil Kantis
12/09/2022, 8:28 PM
But it would be nice if they weren't required 🙂
Emil Kantis
12/09/2022, 8:29 PM
But then it's simply a matter of how the code is parsed
b
Ben Woodworth
12/09/2022, 10:12 PM
Yeah it's probably just because it's lexically ambiguous. Same with extending an abstract class whose last primary constructor arg is a lambda. The lambda needs to be within the parentheses
Ben Woodworth
12/09/2022, 10:15 PM
Kotest and Spek come to mind, with test classes like this