Quantcast
Channel: YouTrackReSharper (RSRP) - Bug and Issue Tracker
Viewing all articles
Browse latest Browse all 106942

RSRP-288341: Do not show 'Expression is always true' in this context

$
0
0
Reporter Vladimir Reshetnikov (nikov) Vladimir Reshetnikov (nikov)
Created Feb 16, 2012 4:21:26 AM
Updated Feb 16, 2012 4:21:26 AM
Priority Normal
Type Bug
Fix versions No Fix versions
State Submitted
Assignee Unassigned
Subsystem No subsystem
Affected versions No Affected versions
Fixed in build No Fixed in build
using System;

class Program
{
    static T Foo<T>(T x)
    {
        if(x is bool)
        {
            return (T) (object) true;
        }

        throw new InvalidOperationException();
    }
}


It is obvious that the expression is true and it cannot be further simplified.
If you apply QF suggested by ReSharper, then the code becomes not compilable:

using System;

class Program
{
    static T Foo<T>(T x)
    {
        if(x is bool)
        {
            return true; // error CS0029: Cannot implicitly convert type 'bool' to 'T'
        }

        throw new InvalidOperationException();
    }
}

Viewing all articles
Browse latest Browse all 106942

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>