import Toybox.Lang; import Toybox.Position; function onPosition(info as Position.Info) as Void { // log("onPosition"); } function initLocationEvents1(config as Number) as Void { Position.enableLocationEvents(Position.LOCATION_CONTINUOUS, method(:onPosition)); } // (:typecheck(false)) function initLocationEvents2(config as Number) as Void { Position.enableLocationEvents(Position.LOCATION_CONTINUOUS, new Method($, :onPosition)); } function initLocationEvents3(config as Number) as Void { Position.enableLocationEvents(Position.LOCATION_CONTINUOUS, new Method($, :onPosition) as Method(loc as $.Toybox.Position.Info) as Void); }
In the 1st case I get:
Cannot find symbol ':method' on type 'self'
It looks like method() only works in classes? I'm not sure why, this really should work, but at least it should be documented.
In the 2nd case I get:
Passing '$.Toybox.Lang.Method' as parameter 2 of poly type 'PolyType<Null or ($.Toybox.Lang.Method(loc as $.Toybox.Position.Info) as Void)>'.
This at least can be worked around by adding the typecheck false annotation (or new Method($, :onPosition2) as Method(loc as Position.Info) as Void), but I feel like this shouldn't be needed, method() and the compiler should be clever enough to work it out.
SDK 8.1.0, typecheck:3, I tried it on fr955 in the simulator