SonarQube C#
  1. SonarQube C#
  2. SONARCS-386

Support nullable types in ternary condition

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.1
    • Component/s: C# Squid Plugin
    • Labels:
      None
    • Number of attachments :
      0

      Description

      The following code must parse properly:

      using System;
      
      class Program
      {
          static void Main(string[] args)
          {
              int? a = false ? new int?(42) : null;
          }
      }
      

      It seems that when on the left hand side, the "new int?(42)" part does parse properly.

        Issue Links

          Activity

          Hide
          Eric Hartmann added a comment -

          Also check the following code (from Michael Rumpf, Another parsing issue, Sonar User):

          BooleanPattern booleanPattern = new BooleanPattern(
            booleanPattern_Old.Operator,
            (booleanPattern_Old.Pattern == BooleanFilter.Yes)
            ? new bool?(true) : (booleanPattern_Old.Pattern == BooleanFilter.No)
            ? new bool?(false) : null);
          
          Show
          Eric Hartmann added a comment - Also check the following code (from Michael Rumpf, Another parsing issue, Sonar User): BooleanPattern booleanPattern = new BooleanPattern( booleanPattern_Old.Operator, (booleanPattern_Old.Pattern == BooleanFilter.Yes) ? new bool?( true ) : (booleanPattern_Old.Pattern == BooleanFilter.No) ? new bool?( false ) : null );
          Hide
          Dinesh Bolkensteyn added a comment -

          Should be good now, ticky one!

          Show
          Dinesh Bolkensteyn added a comment - Should be good now, ticky one!
          Hide
          Dinesh Bolkensteyn added a comment -

          There is a regression, the following does not parse anymore:

          a is T? ((T)a).foo() : bar()
          
          Show
          Dinesh Bolkensteyn added a comment - There is a regression, the following does not parse anymore: a is T? ((T)a).foo() : bar()
          Hide
          Dinesh Bolkensteyn added a comment -

          The regression is fixed, but I found a case that is not covered: SONARDOTNT-331

          Show
          Dinesh Bolkensteyn added a comment - The regression is fixed, but I found a case that is not covered: SONARDOTNT-331
          Hide
          Fabrice Bellingard added a comment -

          Tested!

          Show
          Fabrice Bellingard added a comment - Tested!

            People

            • Assignee:
              Dinesh Bolkensteyn
              Reporter:
              Eric Hartmann
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: