You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2022/07/04 02:42:00 UTC

[jira] [Commented] (GROOVY-8078) Double unary - and + not supported ?

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

Paul King commented on GROOVY-8078:
-----------------------------------

Just an update. Recent versions support mot of these variants (but not all):
{noformat}
Groovy Shell (4.0.3, JVM: 1.8.0_282)
Type ':help' or ':h' for help.
-------------------------------------------------------------------------------
groovy:000> - 3
===> -3
groovy:000> + 3
===> 3
groovy:000> + -3
===> -3
groovy:000> + +3
===> 3
groovy:000> -- 3
===> 2
groovy:000> ++ 4
===> 5
groovy:000> -3
===> -3
groovy:000> +4
===> 4
groovy:000> + + 4
===> 4
groovy:000> - +4
===> -4
groovy:000> - - 5
ERROR org.codehaus.groovy.GroovyBugError:
BUG! Failed to find the original number literal text: -5
        at org.apache.groovy.parser.antlr4.AstBuilder.visitUnaryAddExprAlt (AstBuilder.java:3301)
        at org.apache.groovy.parser.antlr4.AstBuilder.visitUnaryAddExprAlt (AstBuilder.java:378)
        at org.apache.groovy.parser.antlr4.GroovyParser$UnaryAddExprAltContext.accept (GroovyParser.java:8690)
        at groovyjarjarantlr4.v4.runtime.tree.AbstractParseTreeVisitor.visit (AbstractParseTreeVisitor.java:20)
        at org.apache.groovy.parser.antlr4.AstBuilder.visit (AstBuilder.java:4703)
        at org.apache.groovy.parser.antlr4.AstBuilder.visitCommandExpression (AstBuilder.java:2548)
        at org.apache.groovy.parser.antlr4.AstBuilder.visitCommandExprAlt (AstBuilder.java:2533)
        at org.apache.groovy.parser.antlr4.AstBuilder.visitCommandExprAlt (AstBuilder.java:378)
        at org.apache.groovy.parser.antlr4.GroovyParser$CommandExprAltContext.accept (GroovyParser.java:8270)
        at groovyjarjarantlr4.v4.runtime.tree.AbstractParseTreeVisitor.visitChildren (AbstractParseTreeVisitor.java:48) {noformat}

> Double unary - and + not supported ?
> ------------------------------------
>
>                 Key: GROOVY-8078
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8078
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 2.4.8
>         Environment: Windows (but probably generic)
>            Reporter: Tomas Rokicki
>            Priority: Minor
>
> You cannot use a double unary - or +, or combine them:
> groovy:000> - - 3
> groovysh_parse: 2: unexpected token: - @ line 2, column 3.
>    - - 3
>      ^
> groovy:000> - + 3
> groovysh_parse: 2: unexpected token: + @ line 2, column 3.
>    - + 3
>      ^
> groovy:000> - -3
> groovysh_parse: 2: unexpected token: - @ line 2, column 3.
>    - -3
>      ^
> groovy:000> + + 3
> groovysh_parse: 2: unexpected token: + @ line 2, column 3.
>    + + 3
> This is just an annoyance, or perhaps it is intentional.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)