Skip to content

Statically imported fields causing compile error in annotation arrays values #245

@AntonPanikov

Description

@AntonPanikov

If you try to use statically imported fields in annotation array value, it will looks like 'cannot be resolved to a variable' compile error. Actually code compiles and runs fine. It was working about month ago (can not tell exactly version, about mid of November), but right now it is broken.

I am using Groovy-Eclispe: 2.9.2.xx-201612141446-e46

There is simple example:
TestStrings.groovy

package test

interface TestStrings {
    public static final String ONE = 'one'
    public static final String TWO = 'two'
    public static final String THREE = 'three'
}

TestAnnotation.groovy

package test

@interface TestAnnotation {
    String[] value()
}

Test.groovy

package test

import static test.TestStrings.*

class Test {

    @TestAnnotation(value = [ONE, TWO])
    static main(args) {
        println 'hello groovy'
    }

}

Test.groovy will have two compile errors: 'ONE cannot be resolved to a variable' and the same for TWO. If you replace 'String[] value' to just 'String value', then using '@TestAnnotation(value = ONE)' will not cause this error. If you replace ONE/TWO by TestString.ONE/TWO, this will go away also.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions