Hi to all,
I'm trying to remove warnings from my VO imported code.
To remove the "XS0165 Use of unassigned local variable" warning, I checked the "Initialize Local Variables" setting in the project properties.
But I get strange result comparing to the VO behavior. The "local variable initialization" seems to be done in the constructor of the parent class, and all the variables already initialized in a child class before super() or in the PreInit() method are reinitialized durng the super().
For example :
CLASS MyClass
PROTECT oBmp1 AS Bitmap
PROTECT oBmp2 AS Bitmap
END CLASS
CLASS MySubClass INHERIT MyClass
CTOR()
SELF:oBmp1 := Bitmap{ ResourceID{ "MyLogo1", _GetInst() } }
SUPER() // Step by step debugger stops on every line of the MyClass declaration
? SELF:oBmp1, oBmp2 // = null when "Initialize Local Variables is checked" in the project properties
RETURN
METHOD PreInit()
SELF:oBmp2 := Bitmap{ ResourceID{ "MyLogo2", _GetInst() } }
RETURN SELF
END CLASS
Have I misunderstood how this setting works?
Thanks
Thierry
Behavior of "Initialize Local Variables" setting
Re: Behavior of "Initialize Local Variables" setting
Hi Thierry,
Thanks for the report, this looks like a bug to me, the compiler should initialize only local vars (as the name suggests) and not class fields. Or that was intended Robert?
Btw, in c#, if you try to use an unassigned local, you get an error about this, instead of a warning, supposedly because the local might have an unknown value. But if you try to use a private field that never gets assigned, you get a warning instead saying:
"warning CS0649: Field 'nnn' is never assigned to, and will always have its default value 0"
This doesn't make sense to me, local and field vars should either both be guaranteed to get initialized a default value, or both shouldn't. This is why I am not a fan of this XS0165 warning and in XIDE there's an option to automatically always disable it in all apps...
Thanks for the report, this looks like a bug to me, the compiler should initialize only local vars (as the name suggests) and not class fields. Or that was intended Robert?
Btw, in c#, if you try to use an unassigned local, you get an error about this, instead of a warning, supposedly because the local might have an unknown value. But if you try to use a private field that never gets assigned, you get a warning instead saying:
"warning CS0649: Field 'nnn' is never assigned to, and will always have its default value 0"
This doesn't make sense to me, local and field vars should either both be guaranteed to get initialized a default value, or both shouldn't. This is why I am not a fan of this XS0165 warning and in XIDE there's an option to automatically always disable it in all apps...
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
XSharp Development Team
chris(at)xsharp.eu
Re: Behavior of "Initialize Local Variables" setting
Guys,
This seems to be a bug in the compiler.
Can you create a ticket for this?
Robert
This seems to be a bug in the compiler.
Can you create a ticket for this?
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
Re: Behavior of "Initialize Local Variables" setting
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
XSharp Development Team
chris(at)xsharp.eu