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

"Convert to top-level statements" does not correctly handle code excluded by conditional preprocessor directive #78002

Open
just-ero opened this issue Apr 4, 2025 · 2 comments
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@just-ero
Copy link

just-ero commented Apr 4, 2025

Full issue information + repro project:
https://github.com/just-ero/roslyn-issues-repros/tree/main/4.14.0/007_ConvertToTopLevelStatements_PreprocessorDirectives

Version

Roslyn: 4.14.0-3.25178.1 (1a06295)

Steps to Reproduce

  1. Add the following code wherever syntactically applicable:
    class Program
    {
        static void Main()
        {
    #if true
            Console.WriteLine("true");
    #else
            Console.WriteLine("false");
    #endif
        }
    }
    or:
    class Program
    {
        static void Main()
        {
    #if false
            Console.WriteLine("false");
    #else
            Console.WriteLine("true");
    #endif
        }
    }
  2. Apply "Convert to top-level statements" on Main.

Expected Behavior

#if true
    Console.WriteLine("true");
#else
    Console.WriteLine("false");
#endif

and

#if false
    Console.WriteLine("false");
#else
    Console.WriteLine("true");
#endif

respectively.

Actual Behavior

#if true
    Console.WriteLine("true");

and

#if false
        Console.WriteLine("false");
#else
Console.WriteLine("true");

respectively.

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 Issues and PRs which have not yet been triaged by a lead label Apr 4, 2025
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

2 participants