Acknowledged
CIQQA-3055

If return value of Properties.getValue() is used as switch expression, a confusing error is returned: "Permission 'BluetoothLowEnergy' required for '$.Toybox.BluetoothLowEnergy.ScanResult.equals'."

It's understood that the reason for this error is:

- Properties.getValue() returns a PropertyValueType, which is: Application.PropertyKeyType or Lang.Array<Application.PropertyValueType> or Lang.Dictionary<Application.PropertyKeyType, Application.PropertyValueType> or WatchUi.BitmapResource or BluetoothLowEnergy.ScanResult or Complications.Id or WatchFaceConfig.Id or Null

- a switch statement with expression x is implemented by calling x.equals() with each of the case values.

- the use of ScanResult.equals() (or anything in the BLE module) requires the BLE permission

However, this is not going to be immediately (or eventually) obvious to most people.

Furthermore, the knee-jerk response to this problem might be to cast the return value of getValue() to Number (or whatever the expected type should be). This makes the compiler happy, but masks the real possibility that getValue() returns null, in which case the switch statement would crash at runtime, because null.equals() doesn't work. From my POV, if an error message isn't understood, and the "easy way" to "fix" it is to use a cast, that's what people are going to do. And that might lead to actual crashes at runtime.

I'm not gonna pretend I have a good solution for this problem tho.

Original forum post:

https://forums.garmin.com/developer/connect-iq/f/discussion/407160/sdk-8-1-0-compiler-bug-misleading-compiler-error/1914486#1914486

SDK 8.1.0 Compiler BUG: misleading compiler error!

I'm getting this error "Permission 'BluetoothLowEnergy' required for '$.Toybox.BluetoothLowEnergy.ScanResult.equals'." even though my app has nothing to do with BLE and used to compile fine.  The code it is complaining about is the case statements for constants that are enums:
var prop = Properties.getValue(dataViews[i]);
switch (prop) {
    case DATA_VIEW_DAILY:
    case DATA_VIEW_DAILY_WIND:
    case DATA_VIEW_DAILY_PRECIPITATION:
    case DATA_VIEW_DAILY_GRAPH_TEMP_POP:
    case DATA_VIEW_DAILY_GRAPH_WIND_PRESS:
        // not allowed
        Properties.setValue(dataViews[i], DATA_VIEW_HOURLY);
        break;
    default:
        break;
}
  • Or, as a breaking change, move ScanResult to a different module that doesn't require permissions?

  • I don't know if this is possible from a technical perspective, but maybe the solution is that certain symbols in a module could be excluded from requiring permission?

    i.e. Allow BluetoothLowEnergy.ScanResult or BluetoothLowEnergy.ScanResult.equals to be used without permission.