Acknowledged
over 1 year ago

accessing dictionary data is not consistent

this code (I can't reproduce real error on sim or my watch, so snippet)

var d = {0 => "t"), x;

x = d[1];

on some devices causes Array Out Of Bounds Error but

x = d.get(1);

returns null, as is expected.

Error Name: Array Out Of Bounds Error

Occurrences: 20

First Occurrence: 2023-12-10

Last Occurrence: 2023-12-10

Devices:

Venu® Sq. Music Edition: 4.90

fēnix® 6 Pro / 6 Sapphire / 6 Pro Solar / 6 Pro Dual Power / quatix® 6: 26.00

fēnix® 5 Plus: 19.30

Forerunner® 945: 13.00

Forerunner® 945: 13.00

App Versions: 8.6.0

Languages: chs, eng, ita, jpn, spa

Error Name: Array Out Of Bounds Error

Occurrences: 10

First Occurrence: 2023-12-10

Last Occurrence: 2023-12-10

Devices:

Upcoming Wearable: 15.21

Forerunner® 955 / Solar: 17.26

App Versions: 8.6.0

Languages: eng, jpn

Parents
  • A dictionary is an associative array.  Key, value pairs. You are using the [key] notation to retrieve the value which is fine. But I’d expect if you decide to use the array notation and use numeric keys then you’ll see what you’re seeing.  Have you tried using Monkey types to see if it changes the behaviour!

Comment
  • A dictionary is an associative array.  Key, value pairs. You are using the [key] notation to retrieve the value which is fine. But I’d expect if you decide to use the array notation and use numeric keys then you’ll see what you’re seeing.  Have you tried using Monkey types to see if it changes the behaviour!

Children
  • Indeed because it’s an associative array

    You could basically consider it an array of keys and an array of values.  Search for key in first array, then use matching index in second array to pull up the value for that key.

  • and you can see using [] is allowed to dictionary

    Exception: UnexpectedTypeException: Expected Object/Array/Dictionary/ByteArray, given String

  • d[key] should be equivalent to d.get(key), if not, it should be forbidden

    string has probably also associative array of chars but

    var

    str = "abc";

    SYS.println(str[2]);

    Error: Unhandled Exception

    Exception: UnexpectedTypeException: Expected Object/Array/Dictionary/ByteArray, given String