Acknowledged

BUG: Unable to detect scope for the symbol reference 'yourprivatemembernamehere' on private members

Private members of a class expose a weird bug in the typechecking logic of CIQ. Please look at the following class that exposes the following warning on *only* the private member of the class. Public and protected members to not trigger the warning:

WARNING: fenix6xpro: /home/ciq/src/source/bugs/SymbolRefBug.mc:19: Unable to detect scope for the symbol reference 'collision'.
WARNING: fenix6xpro: /home/ciq/src/source/bugs/SymbolRefBug.mc:20: Unable to detect scope for the symbol reference 'collision'.

import Toybox.Lang;

class SymbolRefBug {

  public var noCollision;
  protected var alsoNoCollision;
  private var collision;

  function initialize(args as Dictionary) {

    if (!args.hasKey(:noCollision)) {
      args.put(:noCollision, 1);
    }

    if (!args.hasKey(:alsoNoCollision)) {
      args.put(:alsoNoCollision, 1);
    }

    if (!args.hasKey(:collision)) {
      args.put(:collision, 1);
    }

    System.println(args);

  }
}

This test exposes the warning:

(:test)
module TestSymbolRefBug {
using OPN.Test.More as t;
using Toybox.System as Sys;
import Toybox.Lang;

    (:test)
    function testSymbolRefBug(logger) {
      new SymbolRefBug({});
      return true;
    }
}

Parents
  • Not to state the obvious, but I'm guessing that symbol lookups are only used for public and protected members (as well as global vars/functions), since nobody outside the class itself can access a private member. Similar to how a local variable wouldn't make use of a symbol lookup.

    So the compiler is mad bc it thinks that it should know the context of every symbol lookup, in order to maximize type safety.

    I'm sure you would see the same error if you changed line 19 to something like

    if (!args.hasKey(:foo_bar)) {

    where foo_bar is not used anywhere in your code. (Don't try "foo", as I think it's used in some Garmin library, so it will actually be predefined.)

Comment
  • Not to state the obvious, but I'm guessing that symbol lookups are only used for public and protected members (as well as global vars/functions), since nobody outside the class itself can access a private member. Similar to how a local variable wouldn't make use of a symbol lookup.

    So the compiler is mad bc it thinks that it should know the context of every symbol lookup, in order to maximize type safety.

    I'm sure you would see the same error if you changed line 19 to something like

    if (!args.hasKey(:foo_bar)) {

    where foo_bar is not used anywhere in your code. (Don't try "foo", as I think it's used in some Garmin library, so it will actually be predefined.)

Children
  • It doesn't, you can try it with foo as well, it doesn't emit a warning. Unless you private var foo it.

    You need to have it as a private var otherwise it doesn't emit the warning.

    And it looks to be the same bug as the one markw65 reported. But 7 months later nothing has changed, I don't even know if it is fixed.