Skip to content

IDE0004 - Remove Unnecessary Cast - Invalid suggestion to remove cast that's necessary #53698

@bartdesmet

Description

@bartdesmet

Version Used:

VisualStudio.16.Release/16.10.0+31321.278
C# Tools 3.10.0-4.21269.26+029847714208ebe49668667c60ea5b0a294e0fcb

Steps to Reproduce:

    class E
    {
        private object _o;

        public E First
        {
            get
            {
                return _o is ReadOnlyCollection<E> es ? es[0] : (E)_o;
            }
        }
    }

Expected Behavior:

Code kept as-is.

Actual Behavior:

Suggestion to take away (E) cast:

    class E
    {
        private object _o;

        public E First
        {
            get
            {
                return _o is ReadOnlyCollection<E> es ? es[0] : _o;
            }
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-IDEBugIDE-CodeStyleBuilt-in analyzers, fixes, and refactoringshelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions