Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-8741

Single character GString and '==' with Character or Number

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 3.0.0-alpha-4
    • None
    • None
    • Patch

    Description

      Similar things have been touched before, like GROOVY-2340. But I didn't see exactly this. I'm not sure if single character GStrings are even a thing. Sorry if they aren't.

      But I found the following a bit inconsistent:

      final String S = 'A'
      final Character C = 'A'
      final GString G = "$S"
      final Number N = 65
      
      assert C == S && S == G // 1a
      assert C      ==      G // 1b
      
      assert S == C && G == S // 2a
      //assert      G == C      // 2b, fails, inconsistent with 2a and 1b
      
      assert N == S && S == G // 3a
      //assert N      ==      G // 3b, fails, inconsistent with 3a
      
      assert S == N && G == S // 4a
      //assert      G == N      // 4b, fails, inconsistent with 4a
      

      So, a single character GString equals a character, but only if it is on RHS. It doesn't equal a number, ever. I wonder if it should behave like String here.

      If there's interest in "fixing" this, I've got a patch that allows all those asserts pass and doesn't seem to fail any of the existing test cases.

       

      Attachments

        Activity

          People

            daniel_sun Daniel Sun
            vmj Mikko Värri
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: