WARNING: Cannot determine if container access is using container type

Hello brains trust,

Need some help please.  I receive the compiler warning "Cannot determine if container access is using container type" when using STRICT type checking on the following excerpt of code.  Mind you, the code still runs.

BUT, I can't figure out how to eliminate the warning (it's messing with my OCD).  What am I missing?

function test() as Void {
	var w = null, ti, sz = 6;

	w = Weather.getHourlyForecast();
	if (w != null) {
		for (var j=0; j<sz; j++) {
			ti = Gregorian.info((w[j].forecastTime as Moment), (Time.FORMAT_LONG as DateFormat));
		    // ... more code follows, but irrelevant for this illustration
		}
	}	

}	

  • But levels is a Local var, on which I cannot define which type is.  (It is a string btw)

    so don’t know how fix that…

  • so that's the problem. You can't get the nth character of a string this way. You'll need to use toCharArray() developer.garmin.com/.../String.html

  • I am not trying to get the nth charactar of a String. Levels is an array of strings, and I try to get the nth string from the array

    Anyway i fixed it by adding "as Lang.Array<Lang.String>" to the function which populates the Levels array.

    tx for the help! 

  • again..tx for all the help. I now solved a lot of these warnings (recompiling an old piece of code ;-)) 

    There is are just several warnings left on 2 arrays i cannot find a way to fix: The arrays are om public var in a container, declared as

        public var roomItems as Lang.Dictionary<Lang.Number,WatchUi.MenuItem> = {};  // will contain the objects with the menu items of the rooms
        public var deviceItems as Lang.Dictionary<Lang.Number,DomoticzIconMenuItem or DomoticzToggleMenuItem> = {};  // will contain the objects with the menu items of the devices
    and now for everytime this array is called for whatever reason i get the compiler warning. These are statements like:
                menu.addItem(dz.roomItems[key]);
            _dz.roomItems[currentid].setSubLabel(WatchUi.loadResource(Rez.Strings.STATUS_LOADING_DEVICES));
                menu.addItem(_dz.deviceItems[key]);
                _dz.roomItems[currentid].setSubLabel(null);
    The code works fine though, but i just want to get rid of these compiler warnings...
  • What type does addItem expect? I guess it's either DomoticzIconMenuItem or DomoticzToggleMenuItem but not both and your deviceItems is declared as it contains both types.

  • It is both.  Device with a switch capability are shown as a togglemenuitem in the menu. Other devices e.g sensors Will be presented with a custom item (e.g. A temperature sensor)

  • Hi, I can not figure out how I have to read from an array, it gives always a warning:
    var myElapsedTime = 0;
    var diffTime = 0;
    var arrMilliseconds = new Lang.Array<Lang.Number>[60];
    
    // does Cannot determine if container access is using container type.
    diffTime = myElapsedTime - arrMilliseconds[myActualSecond];
    diffTime = myElapsedTime - (arrMilliseconds[0] as Number);
  • var arrMilliseconds as Lang.Array<Lang.Number> = new Lang.Array<Lang.Number>[60];

  • Thanks, that helped

  • function FillPolygon(dc, sx, sy, dx, dy, theta, points) {
      		theta = theta /360.0 * 2 * Math.PI;
    		var sin = Math.sin(theta);
    		var cos = Math.cos(theta);
    		
    		var coords = new [points.size()];
    		for (var i = 0; i < points.size(); ++i) {
    		
    		// make a copy so as to not modify the points array
    		coords[i] = [ points[i][0] * sx, points[i][1] * sy ];
    		
    		var x = (coords[i][0] * cos) - (coords[i][1] * sin) + dx;
    		var y = (coords[i][0] * sin) + (coords[i][1] * cos) + dy;
    		
    		coords[i][0] = x;
    		coords[i][1] = y;
    		}
    
    		dc.fillPolygon(coords);
    	}

    Same problem above on line 10-16:
    I could not figure out how to avoid the warning message "container"