groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul King <pa...@asert.com.au>
Subject Re: Method with completely capitalized method name, omitting parentheses when calling will cause compilation to fail
Date Wed, 08 Jul 2020 05:08:39 GMT
The Antlr 2 parser is treating any name starting with a capital letter as a
class and then finding a String constant where it expects a variable name
to be.
You can add the parentheses or move your TEST method to a helper class and
then use  astatic import, e.g.:

import static MethodHelper.TEST as test
test 'hello'

Antlr4 parser has been made a bit smarter and can handle this case.

Cheers, Paul.


On Wed, Jul 8, 2020 at 2:58 PM 余佳昕 <yjx_yujiaxin@foxmail.com> wrote:

> In groovy 2.5.*, the following code will fail to compile:
>
> def TEST(String name) {
>     println name
> }
> TEST 'hello'
>
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> ideaGroovyConsole.groovy: 108: unexpected token: hello @ line 108, column 6.
>    TEST 'hello'
>         ^
>
> 1 error
>
> How to solve this problem?
> It works in groovy 3.0.*, but I can't switch to groovy 3.0 yet.
>

Mime
View raw message