xsharp.eu • Musing re "use of unassigned var" warning
Page 1 of 1

Musing re "use of unassigned var" warning

Posted: Wed Nov 25, 2020 6:30 pm
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?

Musing re "use of unassigned var" warning

Posted: Wed Nov 25, 2020 7:55 pm
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