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

Refactoring IDE0053 with preprocessor directives breaks compilation #74137

Open
daniel-kraut-abb opened this issue Jun 25, 2024 · 0 comments
Open
Labels
Area-IDE Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Projects
Milestone

Comments

@daniel-kraut-abb
Copy link

Version Used: Visual Studio 2022 17.9.6 or dotnet-format 5.1.250801, dotnet cli 8.0.204

Steps to Reproduce:

  1. Add lambda code block with single line and preprocessor directives like this:
app.UseSwaggerUI(c =>
{
#if DEBUG
    c.SwaggerEndpoint("/swagger/v1/swagger.json", "API V1");
#else
    c.SwaggerEndpoint("/api/swagger/v1/swagger.json", "API V1");
#endif
});
  1. Use dotnet-format or Visual Studio to refactor suggestion IDE0053 to lambda expression. Produced code looks like this:
app.UseSwaggerUI(c =>
#if DEBUG
    c.SwaggerEndpoint("/swagger/v1/swagger.json", "API V1"));

So the preprocessor directive is never closed, which breaks build and the else part is thrown out completely.

Diagnostic Id:

IDE0053

Expected Behavior:

Could produce something like this:

app.UseSwaggerUI(c =>
#if DEBUG
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "API V1"));
#else
                c.SwaggerEndpoint("/api/swagger/v1/swagger.json", "API V1"));
#endif

Actual Behavior:

Broken compilation, lost code.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 25, 2024
@CyrusNajmabadi CyrusNajmabadi added Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 25, 2024
@CyrusNajmabadi CyrusNajmabadi added this to InQueue in Small Fixes via automation Jun 25, 2024
@CyrusNajmabadi CyrusNajmabadi added this to the Backlog milestone Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Projects
Small Fixes
  
InQueue
Development

No branches or pull requests

2 participants