TLDR: I want to use strict type checking at compile-time but end up with multiple errors, such as "Cannot find symbol ':format' on type 'Null'." -- NO, I do NOT want to stick to "Informative" and NO, I do NOT need opinions about whether or not I should do this or if it is necessary. The compiler has the option and I want to use it as it will likely lead to less run-time IQ! errors.
I am trying to clean up the various compiler warnings in one of my projects, with the ultimate goal of moving from "Interactive" to "Strict". I see the flocsy🤠 ran into this, posted about it, and apparently it was solved but I don't think was ever fixed for instance attributes. Or if it was, then there was a regression in the type checking. As an example, this code will generate a WARNING or ERROR (depending on the type check setting):
var latestInfo = Sensor.getInfo(); if (latestInfo != null) { if (latestInfo.heartRate != null) { var heartRateStr = latestInfo.heartRate.format("%0d"); } }
The current workaround I've found is to use a local variable, which is both extra code and far less clean. And it shoudn't be necessary.
var latestInfo = Sensor.getInfo(); if (latestInfo != null) { var tmpHR = latestInfo.heartRate; if (tmpHR != null) { heartRateStr = tmpHR.format("%0d"); } }
This is happening with SDK 6.2.0
UPDATE: I've posted a bug report: forums.garmin.com/.../strict-type-checking-when-dealing-with-instance-attributes-that-might-be-null