- Open Roslyn.sln at the root of the Roslyn repo in VS2017.
- Open source file <%ROOT%>srcCompilersCSharpPortableParserLanguageParser.cs.
- Navigate to private method IsPossibleParameter (line 4060) and add the highlighted || clause to the default case return statement:
default:
return IsPredefinedType(this.CurrentToken.Kind) || GetModifier(this.CurrentToken) != SyntaxModifier.None;
- Navigate to private method ParseParameterModifiers (line 4234), and replace the existing while (IsParameterModifier(this.CurrentToken.Kind, allowThisKeyword)) with a while (true) loop, add the following if statement at the start of the while loop:
while (true)
{
if (!IsParameterModifier(this.CurrentToken.Kind, allowThisKeyword))
{
if (GetModifier(this.CurrentToken) != SyntaxModifier.None)
{
// Misplaced modifier
var misplacedModifier = this.EatToken();
misplacedModifier = this.AddError(misplacedModifier, ErrorCode.ERR_BadMemberFlag, misplacedModifier.Text);
modifiers.Add(misplacedModifier);
continue;
}
break;
}
...
- Build the solution.
- Set VisualStudioVisualStudioSetup.Next.csproj as the startup project and click on Ctrl + F5 to start a new VS instance with the locally built compiler and IDE toolset.
- Create a new C# class library project, say ClassLibrary, and add the following code:
class Class
{
static void M(readonly int param)
{
}
}
- Verify that there is a single CS0106 diagnostic in the error list for the invalid readonly modifier and also that the editor has a single squiggle.
- Build the project and verify that the build output has a single CS0106 diagnostic.
You can view all the parser changes made in this recipe at https://github.com/mavasani/roslyn/commit/02b7be551b46fa9a8e054c3317bc2ae7957b563c.