Skip to content

'Simplify interpolation' fix should not remove parens around a conditional expressionΒ #49647

Closed

Description

@jnm2

Version Used: VS 16.8.2 and VS 16.9-p1

(How soon is too soon to start reporting bugs assuming top level statements are turned on for new tests by default so I can exclude class C etc?)

class C
{
    void M(bool cond)
    {
        // β„Ή IDE0071 Interpolation can be simplified
        //     ↓
        _ = $"{(cond ? 1 : 2).ToString()}";
    }
}

πŸ’‘ Simplify interpolation:

class C
{
    void M(bool cond)
    {
        // ❌ CS8361 A conditional expression cannot be used directly in a string interpolation because the ':' ends the
        // interpolation. Parenthesize the conditional expression.
        //     ↓↓↓↓↓↓↓↓↓
        _ = $"{cond ? 1 : 2}";
    }
}

Expected:

class C
{
    void M(bool cond)
    {
        _ = $"{(cond ? 1 : 2)}";
    }
}

Activity

  1. added
    Resolution-FixedThe bug has been fixed and/or the requested behavior has been implemented
    and removed
    untriagedIssues and PRs which have not yet been triaged by a lead
    on Dec 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-IDEBugResolution-FixedThe bug has been fixed and/or the requested behavior has been implemented

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions