Acknowledged
CIQQA-3375

bug: SDK 8.2.2 type checker 3 fails to compile code that worked with 8.1.1

The following code (ugly, but I'll try to add it as a comment) compiles with project.typecheck=3 with SDK 8.1.1 or with 8.2.2 but typecheck set to 2, but fails to compile with 8.2.2 and typecheck=3

ERROR: fr955: Bug.mc:56,13: Trying to access an uninitialized variable.
ERROR: fr955: Bug.mc:57,4: Value may not be initialized.

  • import Toybox.Lang;
    import Toybox.Math;
    import Toybox.System;
    import Toybox.WatchUi;

    var WordsInfo as Dictionary<Symbol, Number or Dictionary<Char, Number or ResourceId or Null>> = {
    :words_count => {'c'=>12} as Dictionary<Char, Number>,
    :words_resource => {'c'=>Rez.Strings.AppName} as Dictionary<Char, ResourceId?>
    } as Dictionary<Symbol, Number or Dictionary<Char, Number or ResourceId or Null>>;

    function x(r as ResourceId) as String {
    return WatchUi.loadResource(r) as String;
    }

    function bug(wordsSize as Number, r as Number, wordLength as Number, excludeWordsWithRepeatingLetters as Boolean) as String {
    var wordsCount = WordsInfo[:words_count] as Dictionary<Char, Number>;
    var round = 0;
    var word;
    do {
    var previousWords = 0;
    var letter = 'c';
    var letterWordCount = 0;
    do {
    while (previousWords + letterWordCount <= r && letter != null) {
    previousWords += letterWordCount;
    letter = 'd';
    letterWordCount = wordsCount[letter];
    if (letterWordCount == null) {
    letterWordCount = 0;
    }
    }
    var resource = (WordsInfo[:words_resource] as Dictionary<Char, ResourceId?>)[letter];
    if (resource != null) {
    var wordLengthMinusOne = wordLength - 1;
    var letterWords = x(resource);
    var startIndex;
    startIndex = (r - previousWords) * wordLengthMinusOne;
    word = letter + letterWords.substring(startIndex, startIndex + wordLengthMinusOne) as String;
    if (Math.rand() % 2 == 0) {
    r++;
    word = null;
    }
    if (r >= wordsSize) {
    r = 0;
    round++;
    }
    } else {
    word = "";
    }
    } while (word == null && round <= 1);
    } while (word == null && round <= 1);
    return word != null ? word : "";
    }