Bug 4243 - Bogus CS0219 warnings for assignments with side effects
Summary: Bogus CS0219 warnings for assignments with side effects
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2012-04-04 21:01 UTC by John Costella
Modified: 2012-04-06 19:57 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description John Costella 2012-04-04 21:01:33 UTC
Have been using MD on Windows for the past 6 months, which uses csc.

Compiling the same source code under Linux keeps throwing up bogus CS0219 warnings for assignments that have side effects, where csc does not.

This bug appears to have been reported (it's on old mailing lists on the net) but doesn't seem to be an open bug here.

E.g.

var links = obj.Links;

where Links is a property of obj that is lazily initialised, will cause that property to be initialised, even if the local variable links is never used. There does not appear to be any simple and clean way to cause this behaviour without an assignment. (You can't just leave out the assignment.)

Following old discussions of this, the CS0219 warning should only be issued where the assignment is to something that the compiler knows has no side effects (e.g. assigning a constant). If the assignment has side effects, it is valid and should not be warned about.

I know it's possible to ignore the warning or turn off this warning or drop the warning level down to avoid it (or, even worse, build a whole lot of code to trigger the lazy initialisation of the property), but it would be better to simply make dmcs compatible with csc.

Thanks

john@john-laptop:~$ dmcs --version
Mono C# compiler version 2.10.8.1
Comment 1 Marek Safar 2012-04-05 11:49:47 UTC
Fixed in master.
Comment 2 John Costella 2012-04-06 19:57:23 UTC
Thank you, sir!