raulraja
05/21/2018, 11:59 AMwith
or something similar is introduced in the compiler grammar similar to how varargs
is treated today with the following rules:
1. It has to be declared in arguments position
2. Naming the with
arguments is optional and can be ignored in the first impl.
3. with
arguments are implemented by the bytecode emitter as regular arguments in the same order they are declared so these functions can be invoked from Java explicitly providing the instances values.
4. The compiler will inject the with($ev1) { ... }
scoping blocks around the function bodies.
5. with
is currently a function in the std lib but what it does is just wrap a receiver block so a different function reference may be used:
fun <A, B> withEvidence(f: A.() -> B) : B = f($evA)