Skip to content

Commit

Permalink
Add missing test for CallerArgumentExpression
Browse files Browse the repository at this point in the history
Closes dotnet#52745.
  • Loading branch information
333fred committed Nov 16, 2021
1 parent c7521c9 commit c89048e
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5752,5 +5752,28 @@ static void Main()
ABC
");
}

[Theory]
[InlineData("out")]
[InlineData("ref")]
[InlineData("in")]
public void CallerArgumentExpression_OnRefParameter(string refType)
{
var comp = CreateCompilation(@$"
using System.Runtime.CompilerServices;
#pragma warning disable CS8321
void M(int i, [CallerArgumentExpression(""i"")] {refType} string s)
{{
{(refType == "out" ? "s = null;" : "")}
}}
", targetFramework: TargetFramework.NetCoreApp);

comp.VerifyDiagnostics(
// (5,16): error CS8964: The CallerArgumentExpressionAttribute may only be applied to parameters with default values
// void M(int i, [CallerArgumentExpression("i")] ref string s)
Diagnostic(ErrorCode.ERR_BadCallerArgumentExpressionParamWithoutDefaultValue, "CallerArgumentExpression").WithLocation(5, 16)
);
}
}
}

0 comments on commit c89048e

Please sign in to comment.