Ticket Created
over 3 years ago

CIQQA-1312

int and logical &&

4.1.3 win/eclipse

var x = 2, y= 4;
if(x)         {LOG.println(true);} else {LOG.println(false);}
if(y)         {LOG.println(true);} else {LOG.println(false);}
if(x && y)    {LOG.println(true);} else {LOG.println(false);}

prints

true
true
false <--- bug

  • bug since 2017...

    it'd be better to throw exception "Illegal operator" instead of miscounting

  • > it means system compares the bits - logical  && = bitwise & in this case

    Yeah I reported this in 2017. I'm guessing it's not gonna change.

    forums.garmin.com/.../monkey-c-logical-or-and-and-behave-inconsistently-incorrectly-for-number-types

  • var x = 2, y= 2;
            if(x)         {LOG.println(true);} else {LOG.println(false);}
            if(y)         {LOG.println(true);} else {LOG.println(false);}
            if(x && y)    {LOG.println(true);} else {LOG.println(false);}

    prints

    true
    true
    true

           var x = 2, y= 3;
            if(x)         {LOG.println(true);} else {LOG.println(false);}
            if(y)         {LOG.println(true);} else {LOG.println(false);}
            if(x && y)    {LOG.println(true);} else {LOG.println(false);}

    true
    true
    true

            var x = 129, y= 1;
            if(x)         {LOG.println(true);} else {LOG.println(false);}
            if(y)         {LOG.println(true);} else {LOG.println(false);}
            if(x && y)    {LOG.println(true);} else {LOG.println(false);}

    true
    true
    true

    it means system compares the bits - logical  && = bitwise & in this case

  • I can confirm the bug on Linux as well with ConnectIQ-Version 4.1.3

    using Toybox.Test as t;
    
    module testBug {
      (:test)
      function testBugInt(logger) {
        var x = 2, y = 4;
        t.assertMessage(x && y, "True");
        return true;
      }
    }