Kotlin/kotlin-spec

describe default value evaluation

jbaron opened this issue · 1 comments

Right now the spec doesn't specify when default values are actually evaluated. Would be nice to highlight that this is the case every time when a default value is required, but not in other cases.

So explain that someFunction is invoked every time no value for the parameter is provided and in other cases it is not invoked (so no overhead).

fun test(a:Int = someFunction()) {
 }

This might look like an obvious clarification, but different languages solve this in different ways. So might take away some doubt depending where you coming from.

Hi mate, thanks for your suggestion! The evaluation order (and that the default values are reevaluated on every function call) is actually specified in the function call expression section. To clarify, we will add the forward link to it from the function declaration section and also add a separate note about it.

Cheers!