dotnet / dotnet/format

dotnet format reports false positive for CS1503

Open
#1,516 2 comments 0 reactions 0 assignees View on GitHub
Area-Format untriaged
Dominant language
No language data
Stars
1.9k
Forks
173
Avg merge
10d 13h
Merged PRs (30d)
1

Description

### Describe the bug
In a project where I use F# projects and C# projects I have the following code:
```csharp
public class Test
{
public Guid Id { get; }
public string Text { get; } = "";
}

var test = Array.Empty();
var testById = test.ToDictionary(x => x.Id);

_ = testById[Guid.Empty].Text; // <-- CS1503 with dotnet format
```
When I run `dotnet format --verify-no-changes` I get the following error when `Test` is specified in an F# project:
```
dotnetformatissue\issue\Program.cs(7,31): error CS1503: Argument 1: cannot convert from 'System.Guid' to '?'
```

The compiler doesn't give this error and when `Test` is declared in a C# project the error doesn't appear either.

A workaround is to not use `var testById` but `Dictionary testById`.

_**edit**: I thought it was related to linq, but that is not the case._
### To Reproduce
A full working version of the code can be found at: https://github.com/dnperfors/dotnetformatissue

### Exceptions (if any)

### Further technical details
```
dotnet --info
.NET SDK (reflecting any global.json):
Version: 6.0.100
Commit: 9e8b04bbff

Runtime Environment:
OS Name: Windows
OS Version: 10.0.22000
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\6.0.100\

Host (useful for support):
Version: 6.0.0
Commit: 4822e3c3aa

.NET SDKs installed:
5.0.401 [C:\Program Files\dotnet\sdk]
5.0.403 [C:\Program Files\dotnet\sdk]
6.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.