package Bug //////////////////////////////////////////////////////////////////// ////// Utility //////////////////////////////////////////////////////////////////// /* Basic callbacks */ public interface CallbackNullary function call() function callAndDestroy() this.call() destroy this public interface CallbackUnary function call(T t) function callAndDestroy(T t) this.call(t) destroy this /* Middleware callbacks */ public interface MiddlewareUnary /** Takes ownership of cb */ function call(T t, CallbackUnary cb) /* Helpers */ /** Create a MiddlewareUnary from a CallbackNullary * * Takes cb by reference. * Caller takes ownership of returned value. */ public function mwUnary(CallbackNullary cb) returns MiddlewareUnary return (T t, mwCb) -> begin cb.call() mwCb.callAndDestroy(t) end /** Create a MiddlewareUnary from a CallbackUnary * * Takes cb by reference. * Caller takes ownership of returned value. */ public function mwUnary(CallbackUnary cb) returns MiddlewareUnary return (T t, mwCb) -> begin cb.call(t) mwCb.callAndDestroy(t) end /* List utils */ native println(string msg) public function LinkedList>.call(T0 t0) this.elem.call(t0, e -> println("called")) /** Add CallbackNullarys * * Takes cbs by reference */ public function LinkedList>.add(vararg CallbackNullary cbs) for cb in cbs this.add(mwUnary(cb)) /** Add CallbackUnarys * * Takes cbs by reference */ public function LinkedList>.add(vararg CallbackUnary cbs) for cb in cbs this.add(mwUnary(cb)) //////////////////////////////////////////////////////////////////// ////// Bug Finder //////////////////////////////////////////////////////////////////// class LinkedList T elem function add(T t) this.elem = t class BugClass static let mws = new LinkedList> native testSuccess() init BugClass.mws.add(i -> testSuccess()) BugClass.mws.call(new BugClass)