inline assignment

This forum is meant for questions and discussions about the X# language and tools
Post Reply
stecosta66
Posts: 89
Joined: Mon Sep 26, 2016 12:59 pm
Location: Italy

inline assignment

Post 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
User avatar
Chris
Posts: 4978
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: inline assignment

Post 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).
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
wriedmann
Posts: 3784
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: inline assignment

Post by wriedmann »

Ciao Stefano,
X# is right: the variable lSuccess is assigned but never used, so it can be removed.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
stecosta66
Posts: 89
Joined: Mon Sep 26, 2016 12:59 pm
Location: Italy

Re: inline assignment

Post by stecosta66 »

Hi Chris and Wolfgang,

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

thanks
Stefano
Post Reply