fun caller(g) { g(); // g should be a function, not nil. print g == nil; // out: false } fun callCaller() { var capturedVar = "before"; var a = "a"; fun f() { // Commenting the next line out prevents the bug! capturedVar = "after"; // Returning anything also fixes it, even nil: //return nil; } caller(f); } callCaller();