Well, at least it is either an implementation bug or specification bug I'd say.
https://kotlinlang.org/spec/expressions.html#object-literals - if I don't get it wrong - allows to have no body.
But the examples and implementation enforce one.
Vampire
06/02/2024, 1:38 AM
From a quick look I'd say even the provided antlr grammer would allow having no body
j
Joshua Hansen
06/02/2024, 1:39 AM
Allowing no body would be consistent with the other aspects of the language. Interesting.
Joshua Hansen
06/02/2024, 2:06 AM
After some thought, I think it's a spec error.
Copy code
val test = object : Test() {}
is effectively equivalent to
Copy code
val test = Test()
So why use an anonymous object at all if you're not going to give it body? I think that's the idea.
v
Vampire
06/02/2024, 2:08 AM
val test = object : Test(), Whatever
Vampire
06/02/2024, 2:09 AM
Or if
Test
is abstract but does not have abstract members
j
Joshua Hansen
06/02/2024, 2:10 AM
Ah, yeah. That is a more compelling case than what I originally wrote.