Skip to content

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

Closed
@just-ero

Description

@just-ero

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.

Metadata

Metadata

Assignees

Labels

Area-IDEhelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

Type

Projects

Status

Completed

Relationships

None yet

Development

No branches or pull requests

Issue actions