You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Matt Sheppard (JIRA)" <ji...@apache.org> on 2017/08/14 07:13:00 UTC

[jira] [Commented] (GROOVY-8287) Casting a Matcher to Boolean changes behaviour between 2.3.7 and 2.4.12

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

Matt Sheppard commented on GROOVY-8287:
---------------------------------------

Oh, maybe it's actually a change in the precedence of the cast is applying to the first string, rather than to do with the casting of the Matcher...

With the new version, I see the following by forcing the precedence...

{noformat}
$ tools/groovy/bin/groovy -e "def result = ((Boolean) ('are you a foolish fool?' =~ 'fool')); if (result) {println 'true'} else {println 'false'}"
true
{noformat}

> Casting a Matcher to Boolean changes behaviour between 2.3.7 and 2.4.12
> -----------------------------------------------------------------------
>
>                 Key: GROOVY-8287
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8287
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Matt Sheppard
>
> Ran across some old code which was failing after a groovy version upgrade, and boiled it down to this difference.
> {noformat}
> $ tools/groovy/bin/groovy -v
> Groovy Version: 2.3.7 JVM: 1.8.0_25 Vendor: Oracle Corporation OS: Linux
> $ tools/groovy/bin/groovy -e "def result = ((Boolean) 'are you a foolish fool?' =~ 'fool'); if (result) {println 'true'} else {println 'false'}"
> true
> {noformat}
> vs
> {noformat}
> $ tools/groovy/bin/groovy -v
> Groovy Version: 2.4.12 JVM: 1.8.0_141 Vendor: Oracle Corporation OS: Linux
> $ tools/groovy/bin/groovy -e "def result = ((Boolean) 'are you a foolish fool?' =~ 'fool'); if (result) {println 'true'} else {println 'false'}"
> false
> {noformat}
> Basically, the result of casting the Matcher returned by the '=~' operator to a Boolean used to give me what seems to be the result of calling 'find()' on the matcher, where as the new version seems to always return false.
> Is that change in behaviour between versions expected, or is it a bug?
> Nothing on http://groovy-lang.org/changelogs/changelog-2.4.0.html jumped out at me as related.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)