Musing re "use of unassigned var" warning

This forum is meant for questions and discussions about the X# language and tools
Post Reply
FFF
Posts: 1522
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Musing re "use of unassigned var" warning

Post by FFF »

Above warning i get for code like:

Code: Select all

	
LOCAL aFiles AS FileSystemInfo[]
...
TRY
	aFiles:= aDirs[i]:GetFileSystemInfos("*."+ cExtension) 
CATCH
	System.Environment.Exit(0)
END TRY
...
FOR j:=1 UPTO aFiles:Length
...

AFAIU, aFiles CAN'T be used, if the assignment fails - the app will dissappear prior to using the var.

Initializing aFiles further up would remove the warning, but would i really gain something?
Regards
Karl
(on Win8.1/64, Xide32 2.19, X#2.19.0.2.)
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Musing re "use of unassigned var" warning

Post by robert »

Karl,
The compiler does not really know that System.Environment.Exit(0) will abort the app.
I would assign NULL in the declaration to get rid of the warning:

LOCAL aFiles := NULL AS FileSystemInfo[]

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply