fun interface Foo { ... }
// this works:
data class Baz(val foo: Foo)
val baz = Baz({ ... })
// whereas this doesn't...
fun baz(foo: Foo = { ... })
// it needs to be:
fun baz(foo: Foo = Foo { })
why doesn't the compiler infer Foo as the lambda type in a default value of a function declaration?
It works on initialization of the object, but not as a default value, whether in constructor or in function declarations...
s
Sam
02/01/2023, 1:53 PM
It seems there is special handling for “standalone” SAM conversions when used as function arguments… I can’t find any documentation for it, though. There’s even a named language feature
+SamConversionPerArgument
that is enabled by default, but again, no documentation 😞