eldc
07/24/2017, 9:52 PMval s = run { p.toString() }
val p = 4
fun main() { println(s) }
It produces TypeError: p is undefined. When the first two lines are swapped, it works.konsoletyper
07/25/2017, 6:55 AMeldc
07/25/2017, 7:19 AMeldc
07/25/2017, 7:22 AMobject { ... }
konsoletyper
07/25/2017, 7:27 AM4
will be set as an initial value for p
, whereas s
gets initialized in <clinit>
section.konsoletyper
07/25/2017, 7:27 AMval s = run { p.toString() }
val p = foo()
fun foo() = 4
fun main() { println(s) }
eldc
07/25/2017, 7:46 AMeldc
07/25/2017, 7:48 AMeldc
07/25/2017, 7:49 AMkonsoletyper
07/25/2017, 7:49 AMval s = run { p.toString() }
val p: Any = foo()
fun foo() = 4
fun main() { println(s) }
eldc
07/25/2017, 7:50 AMkonsoletyper
07/25/2017, 7:50 AMeldc
07/25/2017, 7:54 AMunresolved reference: p
konsoletyper
07/25/2017, 7:55 AMkonsoletyper
07/25/2017, 8:19 AMp
in the first line, it would be possible to write code like this:
fun foo() = p.toString()
val s: Any = run(::foo)
val p: Any = run { 42 }
fun main(args: Array<String>) {
println(s)
}
eldc
07/25/2017, 8:30 AMeldc
07/25/2017, 8:32 AMeldc
07/25/2017, 8:33 AMeldc
07/25/2017, 8:33 AM