Incorrect "Nullability doesn't match the target delegate" when tuple element names don't explicitly match
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
**Version Used**: 17.11.0 Preview 3.0
The following code erroneously causes this warning to appear for each lambda in the Error List and at the command line, though squiggles are not shown:
> ⚠️ CS8621 Nullability of reference types in return type of 'lambda expression' doesn't match the target delegate 'Func<(string, object?), ?>' (possibly because of nullability attributes).
```cs
class C
{
void M((string Name, object? Value)[] parameters)
{
_ = parameters.Append(("A", "A")).ToDictionary(
tuple => tuple.Name,
tuple => tuple.Value);
}
}
```
If you name the elements in the tuple expression to exactly match the tuple element names in the collection, the warning goes away.
```cs
class C
{
void M((string Name, object? Value)[] parameters)
{
_ = parameters.Append((Name: "A", Value: "A")).ToDictionary(
tuple => tuple.Name,
tuple => tuple.Value);
}
}
```
For each element where a name is missing or does not exactly match, a nullability warning returns.
Contributor guide
Research direction
The issue provides no repository files, tests, or entry points. Start by reproducing the warning with the supplied C# tuple and ToDictionary examples, then locate the compiler's tuple-name and nullability analysis tests; done means equivalent unnamed tuple elements no longer produce CS8621 while genuine nullability mismatches remain reported.
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
- 35/100