Compiler error CS0843 when built against mono-2.8

Bug #634561 reported by Andrew Jorgensen
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Do Plugins
Fix Released
Low
Robert Dyer

Bug Description

Compiling Evolution.dll...
warning CS2002: Source file `./src/AddressContactDetailItem.cs' specified multiple times
./src/ContactItemSource.cs(39,17): error CS0843: An automatically implemented property `Evolution.ContactAttribute.Detail' must be fully assigned before control leaves the constructor. Consider calling default contructor
./src/ContactItemSource.cs(39,17): error CS0843: An automatically implemented property `Evolution.ContactAttribute.Key' must be fully assigned before control leaves the constructor. Consider calling default contructor
Compilation failed: 2 error(s), 1 warnings

Revision history for this message
Andrew Jorgensen (ajorg) wrote :
Revision history for this message
Robert Dyer (psybers) wrote :

Call me crazy, but this looks like an error in the 2.8 compiler! 'this.Key' and 'Key' are scoped to the same reference and thus their analysis seems to fail incorrectly!

Changed in do-plugins:
status: New → Invalid
Revision history for this message
Andrew Jorgensen (ajorg) wrote :

Nope, they are not the same. When you do "Key = key" you are calling the accessor, which is a method. When you do "this.Key = key" you are making an assignment.

Changed in do-plugins:
status: Invalid → New
Revision history for this message
Robert Dyer (psybers) wrote :

And the inter-procedural analysis should be able to determine that the Key accessor (when setting) does a 'this.Key = key' and thus the analysis (as I said!) is flawed.

Please don't change bug status.

Changed in do-plugins:
status: New → Invalid
Revision history for this message
Robert Dyer (psybers) wrote :

Is the problem here that there is no default constructor defined to assign those 2 properties? Thus if you call a default constructor on this type you wind up with a case where the use-def analysis would indeed be correct in stating those 2 properties were never assigned before use?

Revision history for this message
Robert Dyer (psybers) wrote :

And FYI I am digging through the official language specification for C# to look up the definite assignment rules. Just because I think it should be this way does not necessarily make it so. I'll get back to you.

Revision history for this message
Andrew Jorgensen (ajorg) wrote :

I did try to compile a simpler example of this on .NET and it does emit the same error. Unfortunately it still emits the error when I change it to this.Key. Mono, at least, does allow that.

Revision history for this message
Robert Dyer (psybers) wrote :

Ok that makes more sense to me, because as I said 'this.Key' and 'Key' are semantically equiv.

The question still is why the compilers can't figure out that property is assigned, when it clearly is. If you figure out a solution for .Net let me know - I would prefer that over a solution that works on Mono but is technically still a bug!

Revision history for this message
Andrew Jorgensen (ajorg) wrote :

I am told by my team here that my patch was not correct (and should cause another error) and that the correct fix is more like the attached.

16:13 <alan_> ajorg, The correct fix is to append " : this ()" to the constructor to call the default parameterless one

Also, there is a discussion of this problem on stackoverflow

16:15 <lewing1> ajorg: http://stackoverflow.com/questions/420433/automatic-properties-and-structures-dont-mix

Revision history for this message
Robert Dyer (psybers) wrote :

Have you verified the new patch with the 2.8 compiler?

Changed in do-plugins:
status: Invalid → Confirmed
assignee: nobody → Robert Dyer (psybers)
importance: Undecided → Low
Revision history for this message
Andrew Jorgensen (ajorg) wrote :

Yes, I just built with these changes (the actual attached patch change line endings when I tried it! no idea why) and it does compile on mono 2.8.

Revision history for this message
Andrew Jorgensen (ajorg) wrote :

Some fuzz on line-endings may be required.

Revision history for this message
Robert Dyer (psybers) wrote :

Well now I feel stupid, this whole time I thought we were dealing with a class (not a struct). I am really not sure why they used a struct there... but your patch seems valid in this case.

Fixed in rev 695.

Changed in do-plugins:
status: Confirmed → Fix Committed
Changed in do-plugins:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.