XS0165 Use of unassigned local variable

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

XS0165 Use of unassigned local variable

Post by ic2 »

Another warning which seems incorrect to me:

Code: Select all

Begin Sequence
bErrorHandler := {|oError| _Break(oError)}
bLastHandler := ErrorBlock(bErrorHandler)
oFTP:=FtpAX{}
......
oFTP:Close()

Recover
oFTP:Close() // This is the warning line
End
In the forelast line I get XS0165 Use of unassigned local variable oFTP

But the variable is assigned, and I'd say the FTP connection can just as well be closed in a Recover situation as it is done just a few lines up.

Technically I understand that the assignment of the error handler could cause an exception meaning it reaches the Recover + oFTP:Close before it is assigned.
But practically, this shouldn't be something to warn for I would say?

Dick
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: XS0165 Use of unassigned local variable

Post by Chris »

Hi Dick,

Why not? It is very possible indeed that the var did not get assigned before the error happened. What could be better though is the error message, instead of "Use of unassigned variable", it would be more correct to say "Use of possibly unassigned variable".
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: XS0165 Use of unassigned local variable

Post by robert »

Chris,
I'll change the warning message

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