xsharp.eu • Warning: Variable assigned but never used?
Page 1 of 1

Warning: Variable assigned but never used?

Posted: Fri Nov 12, 2021 12:26 pm
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

Warning: Variable assigned but never used?

Posted: Fri Nov 12, 2021 2:17 pm
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

Warning: Variable assigned but never used?

Posted: Fri Nov 12, 2021 3:09 pm
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