Ticket Created
over 3 years ago

CIQQA-733

multiply case and variable v may not have been initialized error

this code 1A

...

case a1:

//here there is nothing I want to have one code for a1 & a2

//case a2:

...

break;

and  this 1B

..

//case a1:

//here there is nothing I want to have one code for a1 & a2

case a2:

...

break;

no compilation errors

but this code 2

..

case a1:

//here there is nothing I want to have one code for a1 & a2

case a2:

...

break;

generates compilation error "variable v may not have been initialized" but if first is good (all variables initialised) second has to be good too because code 1 there is in 2

sdk 4.0.6
eclipse CIQ plug in: 4.1.0.beta1
eclipse ver: 2021-09 (4.21.0) Build id: 20210910-1417
windows 10
java jre1.8.0_311
watch face
minSdkVersion 2.4.0

Parents
  • Yep I can recreate this. For completeness here's a full test case:

            var v, i;
            i = 1;
            switch (i)
            {
                case 1:
                case 2:
                    v = 123;
                    break;
                default:
                    v = 321;
                //break unnecessary
            }
    
            System.println(v); // warning here: Variable v may not have been initialized in all code paths.
    

    This is clearly a compiler bug.

Comment
  • Yep I can recreate this. For completeness here's a full test case:

            var v, i;
            i = 1;
            switch (i)
            {
                case 1:
                case 2:
                    v = 123;
                    break;
                default:
                    v = 321;
                //break unnecessary
            }
    
            System.println(v); // warning here: Variable v may not have been initialized in all code paths.
    

    This is clearly a compiler bug.

Children
  • not working but error

    BUILD: ERROR: fenix6spro: ... :912: Variable v may not have been initialized.
    BUILD: ERROR: fenix6spro: ... .mc:965: Variable icon may not have been initialized.
    BUILD: Complete
    Aborting launch due to failed build.

    Strange thing that happens when you try to launch, after saving and compilation is no error and  BUILD: Complete.
    Is switch/case analysed in steps? You can write:

    case 1:
      br;//not break

    and error only when launching...

    and you can write also :

    case 1:
      ...
      break;
    case 1:
      ...
      break;

    as Brandon.ConnectIQ says, technically OKbut it should be a small warning (yes, I know it can be case variable: and variable is known in runtime but it's developer's risk when).