// IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR_ES6 //KT-3190 Compiler crash if function called 'invoke' calls a closure // IGNORE_BACKEND: JS // JS backend does not allow to implement Function{N} interfaces fun box(): String { val test = Cached({ it + 2 }) return if (test(1) == 3) "OK" else "fail" } class Cached(private val generate: (K)->V): Function1 { val store = HashMap() // Everything works just fine if 'invoke' method is renamed to, for example, 'get' override fun invoke(p1: K) = store.getOrPut(p1) { generate(p1) } } //from library fun MutableMap.getOrPut(key: K, defaultValue: ()-> V) : V { if (this.containsKey(key)) { return this.get(key) as V } else { val answer = defaultValue() this.put(key, answer) return answer } }