xsharp.eu • Incorrect warning XS2019
Page 1 of 1

Incorrect warning XS2019

Posted: Fri Apr 02, 2021 11:10 am
by ic2
I usually do not care much about warnings, but I thought, why not deal with it.

Currently I have 2 warnings like this:

warning XS0219: The variable 'lFound' is assigned but its value is never used

But lFound is isused!

Local lFound As Logic

oDBF:=DbServer{cDataPath+"tel.dbf",TRUE,FALSE}
If !empty(cSearch)
oDBF:Seek(cSearch)
Else
lFound:=oDBF:GoTo(Int(nRecordnr))
ENDIF


Same for the other error. If I remove the so called "never used" variable declaration I get:


Error XS0103 The name 'lFound' does not exist in the current context

What's wrong with this warning?


Dick

Incorrect warning XS2019

Posted: Fri Apr 02, 2021 11:35 am
by robert
Dick,
The variable is used indeed. You are assigning the result of GoTo() but after the assignment you are not using it. The compiler warns you about that fact.
So you could remove the variable AND the assignment.

Robert

Incorrect warning XS2019

Posted: Sat Apr 03, 2021 4:24 pm
by ic2
Hello Robert,

You're right indeed.

The reason I use this is often that I know that there is a return value I can use if I want. So I leave it as it is, with the warning.

But this gives the same warning and it's definitely used I'd say:

LOCAL cResult AS STRING
cResult:=Self:SqlIssueQuery(cWb,cCs,cDb,cQuery,cQuery2,cQuery3,cQuery4,cQuery5,cVolgQuery,cRecords) // Execute query on webservice
If empty(cResult)
LogEvents("....."0
Endif


Dick

Incorrect warning XS2019

Posted: Sat Apr 03, 2021 8:54 pm
by Chris
Hi Dick,

What is the exact warning message? And can you please post the whole code of this entity?

Incorrect warning XS2019

Posted: Tue Apr 06, 2021 11:04 am
by ic2
Hello Chris,

The warning was XS2019 (see subject) and the code was as provided...but on further investigation that code was not were the warning popped up but one method further were cResult was also assigned, but not used.

The reason that it is easy to overlook this is because of one of the countless flaws of VS. In the error- or warninglist it does not tell which method the warning is in, unlike in VO. In VO I would have seen the method name, doubleclicked the method, opened that method alone and seen at once that the variable was not actually used. In VS you do not see that, I search for the variable and see, in the results, a correct assignment- but in another method.

Dick

Incorrect warning XS2019

Posted: Tue Apr 06, 2021 3:58 pm
by Chris
Hi Dick,

Indeed that's not ideal, but I know another .Net IDE that does show you the entity that the warning/error is referring to :)
But also in VS, when you double click on the warning, the file will be opened and the cursor will be placed in the exact spot of the warning/error, so it should be obvious then what the problem is. If that's not happening, then it is a bug, please report this if you see some problem like that.

Incorrect warning XS2019

Posted: Tue Apr 06, 2021 4:21 pm
by ic2
Hello Chris,
Chris wrote: Indeed that's not ideal, but I know another .Net IDE that does show you the entity that the warning/error is referring to :)/quote]

I assume you mean Xide :) which of course is much better in many respects than VS but unfortunately I need the also a a WPF editor, which is only in VS, a pretty crappy one but what else can you expect from VS.
Chris wrote: But also in VS, when you double click on the warning, the file will be opened and the cursor will be placed in the exact spot of the warning/error, so it should be obvious then what the problem is. If that's not happening, then it is a bug, please report this if you see some problem like that.
Sure that works (even in VS).. But as all code is in the same editor it is also easy to mistakenly end up in another method when you search using the variable from the error.

VS is also one of the few products where I can easily skip 10 or more updates without missing one of changes/additions mentioned for that update. In the past few years I can actually only think of only one useful addition: that CodeLens was added to the Community version, and that doesn't even work in X# :(

Dick