Warning: Variable assigned but never used?

This forum is meant for questions and discussions about the X# language and tools
Post Reply
kitz
Posts: 87
Joined: Wed Nov 29, 2017 8:56 am

Warning: Variable assigned but never used?

Post by kitz »

Hello!
XS 2.8c, Visual Studio 2019 16.11.6, Win 10 Enterprise 20H1

In code

Code: Select all

METHOD HelpAboutDialog() 
	LOCAL oOD AS Info
	
	(oOD := Info{SELF}):Show()
RETURN NIL
I get the warning:
...Standard Shell.prg(87,8 ): warning XS0219: The variable 'oOD' is assigned but its value is never used
Is this intended?
If I omit oOD completely or
make 2 lines of it 1. with assignment, 2. oOD:Show()
there are no warnings anymore.
Just a minor thing, but wanted to ask/report.
BR Kurt
User avatar
wriedmann
Posts: 3644
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Warning: Variable assigned but never used?

Post by wriedmann »

Hi Kurt,

IMHO the compiler is right here: you don't need that variable.

So you can write

Code: Select all

METHOD HelpAboutDialog() 
	
	Info{SELF}:Show()
RETURN NIL
or

Code: Select all

METHOD HelpAboutDialog() 
	LOCAL oOD AS Info
	
	oOD := Info{SELF}
	oOD:Show()
RETURN NIL
Both cases should not show the warning.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Jamal
Posts: 314
Joined: Mon Jul 03, 2017 7:02 pm

Warning: Variable assigned but never used?

Post by Jamal »

Kurt,

Just like Wolfgang said.

May I add, the compiler is basically saying that you declared and assigned a variable for no useful purpose.

Jamal
Post Reply