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

RSRP-275508: Ternary expression to null-coalescing conversion

$
0
0
Reporter Alex Berezoutsky (fergard) Alex Berezoutsky (fergard)
Created Sep 12, 2011 5:30:58 PM
Updated Mar 27, 2012 5:03:10 PM
Priority Major
Type Bug
Fix versions 7.0
State Submitted
Assignee Alexey Kuptsov (alexey.kuptsov)
Subsystem No subsystem
Affected versions 6.0
Fixed in build No Fixed in build
I think there is a very trivial bug with the "'?;' expression can be rewritten as '??' expression" suggestion; it's not Earth-shatteringly urgent but I thought I'd best point it out.

Given the following code Resharper will not suggest the rewrite:

        public void Method(int? value)
        {
            var result = value == null ? 0 : value.Value;
        }

However if I change the code to the following then Resharper will suggest a rewrite:

  public void Method(int? value)
        {
            var result = value == null ? 0 : value;
        }

If executed then the code will be rewritten to:

  public void Method(int? value)
        {
            var result = value ?? 0;
        }

In the first piece of code the ternary operator resolves to an int type.
In the second piece of code the ternary operator actually resolves to an int? type.
In the reformatted code the result is an int type.

Viewing all articles
Browse latest Browse all 106942

Trending Articles



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