xsharp.eu • inline assignment
Page 1 of 1

inline assignment

Posted: Sat Dec 07, 2024 11:48 am
by stecosta66
Hi all,

Using X# 2.21.0.5

I don't know if this has to be reported or not.

In VO I've the following code:

Code: Select all

	LOCAL lSuccess AS LOGIC

	IF lSuccess := ( ALen( auBalancesID ) ) > 0
		// some stuff
	ENDIF
in X#, the same code gives me
XS0219 The variable 'lSuccess' is assigned but its value is never used

if I change the code in:

Code: Select all

	LOCAL lSuccess AS LOGIC

	lSuccess := ( ALen( auBalancesID ) ) > 0
	IF lSuccess
		// some stuff
	ENDIF
then the warning goes away.

It is intended to work this way?

Sorry for newbie question, still learning.

Stefano

Re: inline assignment

Posted: Sat Dec 07, 2024 12:46 pm
by Chris
Hi Stefano,

In the second version, you are using the variable in another statement, so there's no reason for a warning. It could be argued that the local is not really needed, but that's a matter of preference, making the code more readable etc.

In the first case though, what's the point of the inline assignment, if you are indeed not using the local at all later? The compiler assumes that you forgot to use the result, hence the warning.

So yes, this is intended, but of course if you have a reason or just prefer to write code this way, then it's completely up to you, you can ignore the warning, or simply disable it (locally with #pragma warning (0219,off), or globally in the project settings).

Re: inline assignment

Posted: Sat Dec 07, 2024 1:57 pm
by wriedmann
Ciao Stefano,
X# is right: the variable lSuccess is assigned but never used, so it can be removed.
Wolfgang

Re: inline assignment

Posted: Sat Dec 07, 2024 2:41 pm
by stecosta66
Hi Chris and Wolfgang,

indeed the code was written to make it more readable and more easy to debug.

thanks
Stefano