groovy

Static import of properties and fields does not work

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.1-beta-3
  • Fix Version/s: 1.1-rc-1
  • Component/s: None
  • Labels:
    None
  • Environment:
    OS: Win XP
    Groovy Version: 1.1-beta-3
    JVM: 1.6.0_02-b05
  • Number of attachments :
    0

Description

The following doesn't work with Groovy 1.1 beta 3, neither in interpreted nor in compiled mode. Adding 'public' and/or 'final' to the declaration of 'temperature' doesn't change the picture. With beta 2 the program works in compiled but not in interpreted mode.

--------------------------------------------------------

E:\dev\tmp\test>type A.groovy
class A {
static def temperature = 42
}

E:\dev\tmp\test>type B.groovy
import static A.*

class B {
static def main(args) { println temperature }
}

E:\dev\tmp\test>groovy B
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed,
B.groovy: 4: the name temperature doesn't refer to a declared variable or class.
The static scope requires to declare variables before using them. If the variab
le should have been a class check the spelling.
@ line 4, column 35.
static def main(args) { println temperature }
^

1 error

E:\dev\tmp\test>groovyc *.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed,
B.groovy: 4: the name temperature doesn't refer to a declared variable or class.
The static scope requires to declare variables before using them. If the variab
le should have been a class check the spelling.
@ line 4, column 35.
static def main(args) { println temperature }
^

1 error

Activity

Hide
Paul King added a comment -

This is mostly fixed - moved the remaining static error detection parts into staticImportVisitor but I have a hack in place for one part - checking if Jochen has any ideas on a better way.

Show
Paul King added a comment - This is mostly fixed - moved the remaining static error detection parts into staticImportVisitor but I have a hack in place for one part - checking if Jochen has any ideas on a better way.
Hide
Paul King added a comment -

Resolved remaining issue as far as I can tell, tests added

Show
Paul King added a comment - Resolved remaining issue as far as I can tell, tests added
Hide
Paul King added a comment -

No further feedback, assuming fixed

Show
Paul King added a comment - No further feedback, assuming fixed

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: