Bug: incorrect warning message, Unreachable expression code detected

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Don Burden

    Bug: incorrect warning message, Unreachable expression code detected

    We've started converting some applications to the .NET 2.0 framework. When
    compiling in VS 2005, I'm getting a warning on this line:
    return (unitWidth != null ) ? unitWidth : new Unit("0px");

    Looks valid to me, but this gives a warning with "new" underlined saying
    "warning CS0429: Unreachable expression code detected".


  • Ignacio Machin \( .NET/ C# MVP \)

    #2
    Re: incorrect warning message, Unreachable expression code detected

    Hi,

    It looks valid indeed.

    I just wrote this in a project:

    string G( string q)
    {
    return (q != null) ? q : new string('r', 12);
    }

    and it did compiled without warning.
    Can you post the complete method?


    "Don Burden" <nomail@nomail. comwrote in message
    news:ua2Etpv4GH A.2208@TK2MSFTN GP04.phx.gbl...
    We've started converting some applications to the .NET 2.0 framework.
    When compiling in VS 2005, I'm getting a warning on this line:
    return (unitWidth != null ) ? unitWidth : new Unit("0px");
    >
    Looks valid to me, but this gives a warning with "new" underlined saying
    "warning CS0429: Unreachable expression code detected".
    >

    Comment

    • Joanna Carter [TeamB]

      #3
      Re: incorrect warning message, Unreachable expression code detected

      "Don Burden" <nomail@nomail. coma écrit dans le message de news:
      ua2Etpv4GHA.220 8@TK2MSFTNGP04. phx.gbl...

      | We've started converting some applications to the .NET 2.0 framework.
      When
      | compiling in VS 2005, I'm getting a warning on this line:
      | return (unitWidth != null ) ? unitWidth : new Unit("0px");
      |
      | Looks valid to me, but this gives a warning with "new" underlined saying
      | "warning CS0429: Unreachable expression code detected".

      My guess is that your code above this line will never allow unitWidth to be
      null.

      Joanna

      --
      Joanna Carter [TeamB]
      Consultant Software Engineer


      Comment

      • Ignacio Machin \( .NET/ C# MVP \)

        #4
        Re: incorrect warning message, Unreachable expression code detected

        Hi,

        Not even that, I changed my method to :

        string G( )
        {
        string q = "sfsdf";
        return (q != null) ? q : new string('r', 12);
        }

        and I still do not get a warning


        There must be another error somewhere

        --
        --
        Ignacio Machin,
        ignacio.machin AT dot.state.fl.us
        Florida Department Of Transportation


        "Joanna Carter [TeamB]" <joanna@not.for .spamwrote in message
        news:%23aZ2Ufy4 GHA.772@TK2MSFT NGP02.phx.gbl.. .
        "Don Burden" <nomail@nomail. coma écrit dans le message de news:
        ua2Etpv4GHA.220 8@TK2MSFTNGP04. phx.gbl...
        >
        | We've started converting some applications to the .NET 2.0 framework.
        When
        | compiling in VS 2005, I'm getting a warning on this line:
        | return (unitWidth != null ) ? unitWidth : new Unit("0px");
        |
        | Looks valid to me, but this gives a warning with "new" underlined saying
        | "warning CS0429: Unreachable expression code detected".
        >
        My guess is that your code above this line will never allow unitWidth to
        be
        null.
        >
        Joanna
        >
        --
        Joanna Carter [TeamB]
        Consultant Software Engineer
        >
        >

        Comment

        Working...