Implementing a new syntax error in the C# compiler code base
This section will enable Roslyn contributors to make changes to the C# parser to add a new syntax error. The C# parser reports a diagnostic CS0106 (the modifier 'modifier' is not valid for this item) (https://msdn.microsoft.com/en-us/library/3dd3ha66.aspx) when an incorrect modifier is used in symbol declarations such as fields, methods, locals, and so on. For example, the following erroneous code generates three CS0106 instances:
class Class
{
// Error CS0106: The modifier 'async' is not valid for this item
async int field;
// Error CS0106: The modifier 'readonly' is not valid for this item
readonly static void M()
{
// Error CS0106: The modifier 'readonly' is not valid for this item
readonly int local = 0;
System.Console.WriteLine(local);
}
}
However, if you declare a parameter with an incorrect modifier, say readonly int param
, it doesn't generate CS0106, instead it generates...