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.