Forum Cross Platform with Xamarin

Bug in Mono 4.0.0 compiler (read-only auto-properties in C#6)

PhilippeLeybaertPhilippeLeybaert BEMember ✭✭

I couldn't find a better subforum to post this, so I'm putting it here.

There's a bad bug in the Mono 4.0.0 C# compiler related to read-only auto-properties introduced in C# 6. At first I wasn't sure if Mono 4.0.0 was supposed to support the full C# 6 specification but it turns out it does/should.

The following code doesn't compile:

public class MyClass
    Type Type { get; } // compiler error 1

    public MyClass()
        Type = typeof(string); // compiler error 2

Two compiler errors:

error 1: error CS0118: 'System.Type' is a 'type' but a 'variable' was expected
error 2: error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer

This is perfectly valid C# 6 syntax, and it compiles fine in VS2015RC.

Adding a setter to the property fixes the problem. Changing the name of the property also fixes the issue.

I filed a bug for this:



  • PhilippeLeybaertPhilippeLeybaert BEMember ✭✭

    Looks like the bug is confirmed and it's already fixed in the master branch

Sign In or Register to comment.