You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Mikko Värri (JIRA)" <ji...@apache.org> on 2018/08/10 16:35:00 UTC

[jira] [Created] (GROOVY-8741) Single character GString and '==' with Character or Number

Mikko Värri created GROOVY-8741:
-----------------------------------

             Summary: Single character GString and '==' with Character or Number
                 Key: GROOVY-8741
                 URL: https://issues.apache.org/jira/browse/GROOVY-8741
             Project: Groovy
          Issue Type: Bug
            Reporter: Mikko Värri


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:
{code:java}
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
{code}
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.

 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)