SDK 4.2.0 WARNING: Cannot determine if container access is using container type.

Hello,

I get a message on my SIM (yellow text):

Cannot determine if container access uses container type.

What type of container should i use for this code?

This is an OWM feature

function responseCallback(responseCode as Number, data as Dictionary or String or Null) as Void {

var backgroundData as Dictionary;


if (responseCode == 200) {

backgroundData = {
"1" => responseCode,
"2" => Time.now().value(),
"3" => data["main"]["temp"],
"4" => data["weather"][0]["icon"],

};
} else {
backgroundData = {
"1" => responseCode,
"2" => Time.now().value(),
};
}

Background.exit(backgroundData);
}

Thank you

  • I do it on a per-app basis.  Things that I wrote years ago, I turn it off.  It does nothing at runtime (only pre-compile) and if the app has been stable adding type checking to them really doesn't do anything.

  • Hi, I want to ask how the function type_name(obj) works, see the LINK: isn't it for type detection by any chance?

  • yes, it's detecting the type of obj, but in your code (as far as what I saw) you don't need this. It's both slow and adds unnecessary bytes to your code. IMHO in your case yo do know the types. Am I not right? All you need it so cast them properly:

    when you use dict['foo'] then knowing the type you can cast it like: dict['foo'] as Foo

     I think there's an even better way that I saw in the forum but haven't used, when in the declaration of the DIctionary type you can not only declare what types can the values be but you also declare it according to the key. Something like:

    function x(options as {"foo" as String, "bar" as Number}) as Void {}

  • Thanks a lot for the explanation, yes you are right, I know the types in all my code, I just need to learn how to use them correctly in the future...Wink

  • So if I sum it up, it should look like this correctly, for example?

    function responseCallback(responseCode as Number, data as Dictionary or String or Null) as Void {

    var backgroundData as Dictionary;


    if (responseCode == 200) {

    backgroundData = {
    "1" => responseCode,
    "2" => Time.now().value(),
    "3" => data["main"]["temp"],
    "4" => data["weather"][0]["icon"],

    };
    } else {
    backgroundData = {
    "1" => responseCode,
    "2" => Time.now().value(),
    };
    }

    Background.exit(backgroundData);
    }

  • for sure not.

    1. local variables don't have explicit types (var backgroundData as Dictionary). You can put it there, but not needed, and probably ignored by the compiler

    2. you don't need it in this place. Just:

    var backgroundData;
    if (...) backgroundData = {...} else backgroundData = {...};
    and maybe you'll need:
    Background.exit(backgroundData as Application.PropertyValueType)

    but probably not.

  • Ah, so that's the whole problem, but now I don't know what type this parameter should be:

    private var _test as String = "unk";

    Background.exit(_received);
    } else {
    if (data != null) {
    _test = data ["name"];
    data = null;
      }
    }

  • I don't know, because I neither read minds nor know what api you call. Just look at the api (that you use and that returns data) documentation what name is. String is a good guess though, but maybe it's a Dictionary or an Array, who knows