Skip to content

format is not idempotent for #if/#else around assembly attributes #1949

Done

Description

@dhimmel

Description

csharpier format takes two runs to settle on this file, so check rejects the output of a single format. Rerunning format doesn't fix it because the cache skips the file, so only format --no-cache gets check to pass. Reproduces on 1.2.6, 1.3.0 and 1.4.1 in an empty directory with no configuration. Removing either the using or the class makes it idempotent.

Steps to Reproduce

printf 'using System;\n\n#if A\n[assembly: X]\n#else\n[assembly: Y]\n#endif\n\nclass C { }\n' > Repro.cs
csharpier format Repro.cs
csharpier check Repro.cs
using System;

#if A
[assembly: X]
#else
[assembly: Y]
#endif

class C { }

Expected Behavior

check passes on the output of format.

Actual Behavior

The first format writes:

using System;

#if A
[assembly: X]

#else
[assembly: Y]

#endif

class C { }

check then fails:

Error .\Repro.cs - Was not formatted.
  ----------------------------- Expected: Around Line 6 -----------------------------


  #else
  ----------------------------- Actual: Around Line 6 -----------------------------

  #else
  [assembly: Y]

format --no-cache adds a second blank line before #else, after which the file is stable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions