You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2018/08/10 17:15:00 UTC

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

    [ https://issues.apache.org/jira/browse/GROOVY-8741?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16576598#comment-16576598 ] 

ASF GitHub Bot commented on GROOVY-8741:
----------------------------------------

GitHub user vmj opened a pull request:

    https://github.com/apache/groovy/pull/782

    GROOVY-8741: Make single character GString behave like similar String in '=='

    If there's interest to fix [GROOVY-8741](https://issues.apache.org/jira/browse/GROOVY-8741), this might be it.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/vmj/groovy GROOVY-8741

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/groovy/pull/782.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #782
    
----
commit ce830487dbcb86c78b42497bb093c7affda25d9b
Author: Mikko Värri <vm...@...>
Date:   2018-08-10T16:37:47Z

    GROOVY-8741: Add tests and implementation

----


> 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
>            Priority: Major
>
> 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)