dotnet / dotnet/roslyn

CallerArgumentExpression attributes on partial method parameters look at the implemention rather than definition parameter names

Open
#73,483 6 comments 0 reactions 0 assignees View on GitHub
Area-Compilers
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

**Version Used**: fca6e1fcdcded85e69cc32e15acfb6820cd45597

**Steps to Reproduce**: [SharpLab](https://sharplab.io/#v2:EYLgtghglgdgNAExAagD4AEAMACdBGAOgCUBXGAFyjAFMCBhAezAAcoAbagJwGUuA3KAGNqAZwDcAWABQ09AGZszCJ0oQ2uAEzY60gN7Tsh3AqUqoa3ABZsAWTwAKfDghxsAbTpqOnAIKcA5iQ0FACiAB7MnKIiUAww9gBEEAkAlAC6uHiYAPzYwNgAvNgwJGxsKWLYAPRV2ADuyjCw/trcABwAnABsciDYACoAFtTaXlx+gcHk4ZHRsTA+5OScUMAk5CMQzMxsUNQI2OQMisoQNBuc2ADkAJ5X9ezqgxB8IzDH1ABmn9SC5ATYACS5GwUBE2C2Oz2BzqUHIgwhMFBMD4aigB1MZ2oF2KWIIBiM8hOZgs6GsdkcWWwYVcTlyNxS2F02AAvgTDOzjMTVOoybYNJTnK4PGNfAEgtRQhEoiIYnFEsl0pkcnlCsVSuVKjVsAwANacommHlWfmCiG0rK5YCM5lsqRGbAG8n2FKc/T2h1GbUAcUlXC8N1cgi82BiG3BJBEI3hIwQX1gcPm3OJWJxMCxIk5DopED6CTwqS1tT1WaMFLCeYLFWqtS4nAYnE5dpZQA===)

```cs
using System.Runtime.CompilerServices;

public partial class C
{
public partial void M1(string a, [CallerArgumentExpression("a")] string? b = null); // warning CS8963: The CallerArgumentExpressionAttribute applied to parameter 'y' will have no effect. It is applied with an invalid parameter name.
public partial void M1(string x, string? y) { }

public partial void M2(string a, [CallerArgumentExpression("a")] string? b = null); // ok
public partial void M2(string a, string? b) { }

void M()
{
// Call sites use the definition part parameter names
M1(a: "1"); // ok
M1(x: "1"); // error
}
}
```

**Expected Behavior**: The definition part parameter name is used to decide what parameter to include a caller argument expression for

**Actual Behavior**: The implementation part parameter name is used

[caller-argument-expression.md](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-10.0/caller-argument-expression.md) does not appear to specify what should happen here.

Note that using the attribute on the implementation part results in the attribute being ignored in source. So, it feels like the attribute's parameter name references should be oriented around the declaration where usage of the attribute is supported.

Contributor guide

Open the contributing guide

Research direction

Reproduce the partial-method case in the linked SharpLab example, then read the caller-argument-expression proposal and trace how definition and implementation parameter names are resolved. The payload names no repository files or tests; done means a regression test captures the expected definition-name behavior and the diagnostic and call-site results are consistent.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.