[Mono-bugs] [Bug 651305] New rule for misused as operator

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed Nov 10 21:10:20 EST 2010


https://bugzilla.novell.com/show_bug.cgi?id=651305

https://bugzilla.novell.com/show_bug.cgi?id=651305#c1


Sebastien Pouliot <spouliot at novell.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |spouliot at novell.com
           Severity|Normal                      |Enhancement

--- Comment #1 from Sebastien Pouliot <spouliot at novell.com> 2010-11-11 02:10:19 UTC ---
Do you mean it's useless because we know 'o' is null ? (see a) so the condition
could be optimized away (e.g. automatically by a compiler or manually by a
gendarme defect)

Or (my guess ;-) because 'o as string' will return null anyway if 'o' is null ?
(see b)


(a) 
using System;
class Program {
    static void Main ()
    {
        Console.WriteLine (AsString (null));
    }

    static string AsString (object o)
    {
        string a = o == null ? null : o as string;
        return a;
    }
}

(b)
using System;
class Program {
    static void Main ()
    {
        object o = null;
        string a = o == null ? null : o as string;
        Console.WriteLine (a);
    }
}

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list