xsharp.eu • Warning XS0165 Use of possibly unassigned local variable xxx
Page 1 of 1

Warning XS0165 Use of possibly unassigned local variable xxx

Posted: Tue Oct 01, 2024 7:34 pm
by ic2
This is probably not preventable but basically the warning is incorrect:

Warning XS0165 Use of possibly unassigned local variable cXXX

Code:

Code: Select all

local cXXX as string

if (some condition)
  cXXX:="A"
else
  cXXX:="B"
endif
I understand that I can prevent the warning by assigning some dummy value in the initialization but the warning is incorrect in the above code (The if..else..endif always runs, is not conditional)

Dick

Re: Warning XS0165 Use of possibly unassigned local variable xxx

Posted: Tue Oct 01, 2024 8:08 pm
by robert
Dick,

There must be something else. When I try this with X# 2.20 then this compiles without warnings.

Code: Select all

FUNCTION Start as void
    local cVar as string
    IF Time() < "12:00"
        cVar := Time() + " AM"
    ELSE
        cVar := Time() + " PM"
    ENDIF
    ? cVar
    WAIT
    RETURN
Robert

Re: Warning XS0165 Use of possibly unassigned local variable xxx

Posted: Wed Oct 02, 2024 10:02 am
by ic2
Hello Robert,

Hmm, as I assigned something to all the variables in the meantime and simplified the code for posting I can't find it back to check if something in the code made the warning valid after all.

If I encounter the warning again I will double check if something could cause it. As you tested the code below I assume for now I must have missed something that makes the warning valid.

Dick