带点的Groovy静态方法

带点的Groovy静态方法,groovy,Groovy,为什么此代码会出现编译错误: class SomeList { final String field SomeList(String field) { this.field = field } static SomeList "Regular name of method"() { return new SomeList("Regular name of method") } static SomeList

为什么此代码会出现编译错误:

class SomeList {

    final String field

    SomeList(String field) {
        this.field = field
    }

    static SomeList "Regular name of method"() {
        return new SomeList("Regular name of method")
    }

    static SomeList "Name with.dot"() {
        return new SomeList("Name with.dot")
    }
}

class SomeListTests {

    @Test
    def "some list test"() {
        //given
        SomeList list = SomeList()

        //when
        list."Regular name of method"()

        //then
        //compilation error
    }
}
错误消息:

错误:Groovyc:在编译example-project的测试时\u test:BUG!源单元“/home/alex/Projects/example project/src/test/groovy/SomeListTests.groovy”中的“语义分析”阶段出现异常加载类SomeList时出现问题

我在文档中没有找到任何方法名称作为字符串的限制

当我使用GroovyShell创建main方法并尝试使用该方法启动脚本时,它会编译

class Main {
    public static void main(String[] args) {
        GroovyShell shell = new GroovyShell()
        shell.run(new File("path/to/Script.groovy"), Collections.emptyList())
        println "Everything is cool"
    }
}
这是Script.groovy:

SomeList."Regular name of method"()
SomeList."Name with.dot"()

我在IDEA中创建
Test.groovy
文件作为
groovy脚本
文件:

import org.junit.Test

class SomeList {

    final String field

    SomeList(String field) {
        this.field = field
    }

    static SomeList "Regular name of method"() {
        return new SomeList("Regular name of method")
    }

    static SomeList "Name with.dot"() {
        return new SomeList("Name with.dot")
    }
}

class SomeListTests {

    @Test
    void "some list test"() {
        //given
        SomeList list = new SomeList()

        //when
        println list."Regular name of method"()

        //then
        println list."Name with.dot"()
    }
}
这对我来说很好。我正在使用Groovy 2.4.15。 输出为:

SomeList@cb51256
SomeList@59906517

Dot(.)opreator不能用在方法名中,但当我使用GroovyShell时,它运行的是哪个版本的groovy<代码>错误错误通常是应该在
build.gradle
中报告的错误2.4.15。执行
/gradlew测试
会导致任务的
执行失败:compileTestGroovy'>类SomeList中的非法方法名“name with.dot”
在groovy jira中创建了一个bug,这真的很奇怪。。。我在build.gradle和我的机器上都有2.4.15,但即使我尝试在IDEA中启动测试或执行
/gradlew测试
我也有编译错误您的操作系统和java版本是什么?我可以尝试在另一个环境中重现这个问题。当然,您的代码中存在什么
SomeList=
new
SomeList()
Linux 16.04和Java 1.8.0\u 171。是的,我添加了
新的
,但没有任何更改。即使我只添加导入
SomeList
而不使用它,我也有编译错误。您使用Spock进行测试吗?如果是,什么版本?是的,我使用spock v1.1。但在这个示例代码中,我没有使用它。它是纯JUnitV4.12