Warning XS0165 Use of possibly unassigned local variable xxx

This forum is meant for questions and discussions about the X# language and tools
Post Reply
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Warning XS0165 Use of possibly unassigned local variable xxx

Post 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
User avatar
robert
Posts: 4515
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Warning XS0165 Use of possibly unassigned local variable xxx

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Re: Warning XS0165 Use of possibly unassigned local variable xxx

Post 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
Post Reply