Skip to content

Commit

Permalink
Fix for 8402
Browse files Browse the repository at this point in the history
member declaration parse should not be considered not advanced when "ref" keyword was consumed.

Fixes dotnet#8402
  • Loading branch information
VSadov committed Feb 18, 2016
1 parent d098a0c commit f1d2a6a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,7 @@ private TypeDeclarationSyntax ParseClassOrStructOrInterfaceDeclaration(SyntaxLis
var saveTerm2 = _termState;
_termState |= TerminatorState.IsPossibleMemberStartOrStop;

var memberOrStatement = this.ParseMemberDeclarationOrStatement(kind, name.ValueText);
var memberOrStatement = this.ParseMemberDeclarationOrStatement(classOrStructOrInterface.Kind, name.ValueText);
if (memberOrStatement != null)
{
// statements are accepted here, a semantic error will be reported later
Expand Down Expand Up @@ -2500,7 +2500,7 @@ private MemberDeclarationSyntax ParseMemberDeclarationOrStatement(SyntaxKind par
// We need to consume a bad member and try again.
if (explicitInterfaceOpt == null && identifierOrThisOpt == null && typeParameterListOpt == null)
{
if (attributes.Count == 0 && modifiers.Count == 0 && type.IsMissing)
if (attributes.Count == 0 && modifiers.Count == 0 && type.IsMissing && refKeyword == null)
{
// we haven't advanced, the caller needs to consume the tokens ahead
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2475,6 +2475,34 @@ public void TestClassMethodWithRefReturn()
Assert.Equal(SyntaxKind.None, ms.SemicolonToken.Kind());
}

public void TestClassMethodWithRef()
{
var text = "class a { ref }";
var file = this.ParseFileExperimental(text);

Assert.NotNull(file);
Assert.Equal(1, file.Members.Count);
Assert.Equal(text, file.ToString());
Assert.Equal(1, file.Errors().Length);

Assert.Equal(SyntaxKind.ClassDeclaration, file.Members[0].Kind());
var cs = (TypeDeclarationSyntax)file.Members[0];
Assert.Equal(0, cs.AttributeLists.Count);
Assert.Equal(0, cs.Modifiers.Count);
Assert.NotNull(cs.Keyword);
Assert.Equal(SyntaxKind.ClassKeyword, cs.Keyword.Kind());
Assert.NotNull(cs.Identifier);
Assert.Equal("a", cs.Identifier.ToString());
Assert.Null(cs.BaseList);
Assert.Equal(0, cs.ConstraintClauses.Count);
Assert.NotNull(cs.OpenBraceToken);
Assert.NotNull(cs.CloseBraceToken);

Assert.Equal(1, cs.Members.Count);

Assert.Equal(SyntaxKind.IncompleteMember, cs.Members[0].Kind());
}

private void TestClassMethodModifiers(params SyntaxKind[] modifiers)
{
var text = "class a { " + string.Join(" ", modifiers.Select(SyntaxFacts.GetText)) + " b X() { } }";
Expand Down

0 comments on commit f1d2a6a

Please sign in to comment.