Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet format - Simplify interpolation (IDE0071) - false positive with Enum and FormattableString #40347

Closed
JackMcBride98 opened this issue Apr 22, 2024 · 4 comments
Labels
Area-Format untriaged Request triage from a team member

Comments

@JackMcBride98
Copy link

Describe the bug

We have the below Enum

public enum EmployeeType
{
    Azure,
    Manual,
}

Then when using FormattableSqlString

await dataContext.Database.ExecuteSqlInterpolatedAsync(
    $"UPDATE Employees SET Discriminator = {EmployeeType.Azure.ToString()}, AzureId = {azureId} WHERE EmployeeId = {employee.EmployeeId};");

This sets the Discriminator to "Azure". Without the .ToString() call on the enum, it sets it to 0

Running dotnet format removes the .ToString() call on the EmployeeType enum, which changes the behaviour.
I've fixed for now by using nameof(), but this defo seems an issue.

Is this the correct place for this issue?

To Reproduce

public enum Test
{
    A,
    B
}
FormattableString x = $"{Test.A.ToString()}"

Run dotnet format on a project with this code in.

TargetFramework - net8.0

Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Request triage from a team member label Apr 22, 2024
@KalleOlaviNiemitalo
Copy link
Contributor

This seems a duplicate of dotnet/roslyn#47956.

@KalleOlaviNiemitalo
Copy link
Contributor

dotnet/roslyn#47956 was fixed in dotnet/roslyn#76830. I think this could be closed now.

@JackMcBride98
Copy link
Author

Yes looks like that has been fixed. Nice one 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Format untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

3 participants