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

RSRP-469376: Merge sequential checks inverts the logic

$
0
0
Reporter Aart Jan Kaptijn (omeaart) Aart Jan Kaptijn (omeaart)
Created Apr 23, 2018 1:37:19 PM
Updated Apr 23, 2018 1:37:19 PM
Subsystem No Subsystem
Assignee Unassigned
Priority Normal
State Submitted
Type Bug
Fix version No Fix versions
Affected versions 2018.1
Fixed In Version ReSharper Undefined
VsVersion VS 2017 RTM

The program below illustrates the issue. Resharper suggests to merge the sequential checks for hasValue and hasNoValue. The suggestions are applied in hasValueResharper and hasNoValueResharper.

The output of this program is:

HasValue: True
HasValueResharper: False
HasNoValue: False
HasNoValueResharper: True

The Program:

using System;
using System.Collections.Generic;

namespace TestApp1
{
  class Program
  {
    static void Main(string[] args)
    {
      var class1 = new Class1
      {
        Class2 = new Class2
        {
          Integer = 1
        }
      };

      var hasValue = class1.Class2 != null && class1.Class2.Integer.HasValue;
      var hasNoValue = class1.Class2 == null || !class1.Class2.Integer.HasValue;
      var hasNoValueResharper = (class1.Class2?.Integer).HasValue;
      var hasValueResharper = !(class1.Class2?.Integer).HasValue;

      Console.WriteLine($"HasValue: {hasValue}");
      Console.WriteLine($"HasValueResharper: {hasValueResharper}");
      Console.WriteLine($"HasNoValue: {hasNoValue}");
      Console.WriteLine($"HasNoValueResharper: {hasNoValueResharper}");
      Console.ReadLine();
    }
  }

  public class Class1 {
    public Class2 Class2 { get; set; }
  }

  public class Class2
  {
    public int? Integer { get; set; }
  }
}

Viewing all articles
Browse latest Browse all 106942

Trending Articles



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