https://kotlinlang.org logo
Title
d

dave08

02/01/2023, 11:52 AM
Any reason why:
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?
s

Sam

02/01/2023, 1:04 PM
“this works” — does it? Not for me 🤔 https://pl.kotl.in/Rez5aNt4o
d

dave08

02/01/2023, 1:28 PM
Yeah, sorry, I just corrected the example...
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 😞