typedef ISportProfile as interface {
var sport as Activity.Sport?; // either nullable or not
var subSport as Activity.SubSport?;
};
function useMeters(sportProfile as ISportProfile?) as Boolean {
return sportProfile != null && /*sportProfile.sport == Activity.SPORT_RUNNING &&*/ sportProfile.subSport == Activity.SUB_SPORT_TRACK;
}
function foo() as Void {
var currentWorkoutStepInfo = Activity.getCurrentWorkoutStep();
var use1 = useMeters(currentWorkoutStepInfo /* as ISportProfile? */);
var profileInfo = Activity.getProfileInfo();
var use2 = useMeters(profileInfo);
}
depending whether I add or remove the "?" on the sport field in the interface I get a compilation error either because I pass WorkoutStepInfo that has sport as Sport or because I pass ProfileInfo that has sport as Sport or Null. Is there a way to make both work with strict type check?
ERROR: enduro3: Foo.mc:12,16: Passing 'PolyType<Null or $.Toybox.Activity.WorkoutStepInfo>' as parameter 1 of poly type 'PolyType<Null or interface { var subSport as Null or $.Toybox.Activity.SubSport; var sport as Null or $.Toybox.Activity.Sport; }>'.
or
ERROR: enduro3: Foo.mc:14,20: Invalid '$.Toybox.Activity.ProfileInfo' passed as parameter 1 of type 'PolyType<Null or interface { var subSport as Null or $.Toybox.Activity.SubSport; var sport as $.Toybox.Activity.Sport; }>'.
I feel like having a field's type "Foo?" and passing an object with that field as "Foo" should be allowed. Is this a compiler bug or is there some real reason that I am missing?
SDK 8.4.1
P.S: adding "(:typecheck(false))" annotation to useMeters doesn't help, but even if it would I wouldn't consider it a real solution
P.S2: casting WorkoutStepInfo to ISportProfile seems to work but still feels hacky