bug: strange compiler behavior: tiny change => nonsense error in other place

I've encountered some strange things in the compiler lately. It turns out it's not SDK version related (at least it happens also in SDK 8.4.0, 8.3.0, 8.2.3, 8.1.1). I think it is somehow related to project size and optimization (maybe just how the compiler works).

What happens is that I do a tiny little change somewhere in my code, and then a totally nonsense error pops up in a different place. I have now an example (though it's just to demonstrate the issue, I don't think anyone will be able to reproduce this without my project) where this happens within a file. This is the file:

import Toybox.Graphics;
import Toybox.Lang;

/* 
 * 205 x 148 SQUARE FONT GROUP A
 * DEVICES:
 * - vivoactive
 */

const LAYOUT_LINE1 = 15;
const LAYOUT_LINE2 = 42;
const LAYOUT_LINE3 = 95;
const LAYOUT_LINE4 = 120;
const LAYOUT_stepGoalProgressOffsetX = 0;
const LAYOUT_stepGoalProgressHeight = 3;
const LAYOUT_centerOffsetX = 4;
const LAYOUT_clockY = 5;
const LAYOUT_clockOffsetX = 0;
const LAYOUT_topRowY = LAYOUT_LINE1 + 12;
const LAYOUT_middleRowOffsetX = 5;
const LAYOUT_middleRowLabelY = LAYOUT_LINE2 + 8;
const LAYOUT_middleRowValueY = LAYOUT_LINE2 + 8 + 25;

// line with small change
const LAYOUT_heartRateIconY = LAYOUT_LINE3 - 20;

const LAYOUT_heartRateIconHRZY = 107;
const LAYOUT_heartRateIconWidth = 20;
const LAYOUT_heartRateIconHRZWidth = 28;
const LAYOUT_heartRateIconXOffset = 2;
const LAYOUT_heartRateIconHRZXOffset = 2;
const LAYOUT_heartRateTextY = LAYOUT_middleRowLabelY;
const LAYOUT_bottomRowUpperTextY = 160;
const LAYOUT_bottomRowLowerTextY = 185;
const LAYOUT_bottomRowIconX = 4;
const LAYOUT_bottomRowIconY = 155;
const LAYOUT_batteryY = 222;
const LAYOUT_batteryX = 0;
const LAYOUT_batteryWidth = 49;
const LAYOUT_batteryHeight = 22;
const LAYOUT_timeFont = Graphics.FONT_XTINY;
const LAYOUT_topRowFont = Graphics.FONT_MEDIUM;
const LAYOUT_heartRateFont = Graphics.FONT_MEDIUM;
const LAYOUT_middleRowLabelFont = Graphics.FONT_XTINY;
const LAYOUT_middleRowValueFontShrunk = Graphics.FONT_LARGE;
const LAYOUT_middleRowValueFont = Graphics.FONT_NUMBER_MEDIUM;
const LAYOUT_bottomRowFont = Graphics.FONT_MEDIUM;

// line with error
const LAYOUT_batteryFont = Graphics.FONT_XTINY;

const LAYOUT_eightColourPalette = false;
const LAYOUT_GPS_ICON_X = 58;
const LAYOUT_GPS_ICON_Y = 211;
const LAYOUT_WIDTH = 205;

If the line is:

const LAYOUT_heartRateIconY = LAYOUT_LINE3;

then everything compiles. But if I change the line to:

const LAYOUT_heartRateIconY = LAYOUT_LINE3 - 20;
then there's a compilation error in the LAYOUT_batteryFont line:
ERROR: vivoactive: Layout.mc:45: Member '$.LAYOUT_batteryFont' is untyped.
Maybe if more people experience similar strange things we might be able to pinpoint it so that Garmin will be able to fix it. I'm not even opening a bug-report as I don't feel like it'll be very useful at this point. I'll send my project to [email protected], maybe they'll be able to find it.
  • I remember I've also had strange errors when I immediately initialized variables in the declaration. 

    It may be worth a try to change your consts to vars and then initialize them in the initialization function 

  • That would be against the purpose of using constants. In this case it's that the compiler replaced every usage by the value at compile time. If it was const array, then I could change to variable

  • Yesterday I ran into a runtime error that has been sitting there for ages (division by 0.0), after I made a change to another line. I was confused how it ever did work though :D 

  • Division by zero is usually not a compile time thing (unless you divide by a constant that is 0) and also it's not a compiler bug but a bug in your code.

  • It's from the simulator. I tried my current release code and that also gives an error now, however I'm glad to see in production on the devices it still works without problems, I'll make an extra release to prevent problems this week. My guess is that it has not been a division by zero for floats not to be completely zero, so I guessed they might have fixed that.

    I already gave up on setting constants using calculations from other constants somewhere in a very early stage.

  • Curious: if you try the current release code with 8.3.0 instead of 8.4.0, does it also give the error (both sim and real device)?

  • The strange thing is it didn't happen immediately after 8.4.0. I checked and the error also appears with 8.3.0, in production ERA shows no errors.

    I don't know if updates to the simulator also are rolled back when I choose to use sdk 8.3.0, my guess is not.

    Also the activity data settings do not trigger complications to update from the simulator, also  in both versions, don't know since when. 

  • updates to the simulator

    If you mean updates to the devices => no

    if you mean the simulator => every time you change the SDK version in the SDKManager close the simulator window, so it'll open up a new simulator from the SDK you choose.