Skip to content

Commit

Permalink
Test readonly ref in cref
Browse files Browse the repository at this point in the history
  • Loading branch information
jjonescz committed Jul 20, 2023
1 parent d2c7205 commit da231e3
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6750,6 +6750,57 @@ static void verify(CSharpCompilation compilation)
}
}

[Fact]
public void CRef_RefReadonlyParameter_ReadonlyRef()
{
var source = """
class Test
{
void M(ref readonly int x)
{
}

/// <summary>
/// <see cref="M(readonly ref int)"/>
/// </summary>
void S()
{
}
}
""";

verify(CreateCompilation(source, parseOptions: TestOptions.Regular11.WithDocumentationMode(DocumentationMode.Diagnose)).VerifyDiagnostics(
// (3,16): error CS8652: The feature 'ref readonly parameters' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.
// void M(ref readonly int x)
Diagnostic(ErrorCode.ERR_FeatureInPreview, "readonly").WithArguments("ref readonly parameters").WithLocation(3, 16),
// (8,20): warning CS1584: XML comment has syntactically incorrect cref attribute 'M(readonly ref int)'
// /// <see cref="M(readonly ref int)"/>
Diagnostic(ErrorCode.WRN_BadXMLRefSyntax, "M(").WithArguments("M(readonly ref int)").WithLocation(8, 20),
// (8,22): warning CS1658: ) expected. See also error CS1026.
// /// <see cref="M(readonly ref int)"/>
Diagnostic(ErrorCode.WRN_ErrorOverride, "readonly").WithArguments(") expected", "1026").WithLocation(8, 22)));

var expectedDiagnostics = new[]
{
// (8,20): warning CS1584: XML comment has syntactically incorrect cref attribute 'M(readonly ref int)'
// /// <see cref="M(readonly ref int)"/>
Diagnostic(ErrorCode.WRN_BadXMLRefSyntax, "M(").WithArguments("M(readonly ref int)").WithLocation(8, 20),
// (8,22): warning CS1658: ) expected. See also error CS1026.
// /// <see cref="M(readonly ref int)"/>
Diagnostic(ErrorCode.WRN_ErrorOverride, "readonly").WithArguments(") expected", "1026").WithLocation(8, 22)
};

verify(CreateCompilation(source, parseOptions: TestOptions.RegularNext.WithDocumentationMode(DocumentationMode.Diagnose)).VerifyDiagnostics(expectedDiagnostics));
verify(CreateCompilation(source, parseOptions: TestOptions.RegularPreview.WithDocumentationMode(DocumentationMode.Diagnose)).VerifyDiagnostics(expectedDiagnostics));

static void verify(CSharpCompilation compilation)
{
var model = compilation.GetSemanticModel(compilation.SyntaxTrees.Single());
var cref = (NameMemberCrefSyntax)GetCrefSyntaxes(compilation).Single();
Assert.Empty(cref.Parameters.Parameters);
}
}

[Fact]
public void Cref_TupleType()
{
Expand Down

0 comments on commit da231e3

Please sign in to comment.