Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Won't Fix
-
Affects Version/s: 1.5.4
-
Fix Version/s: None
-
Component/s: command line processing
-
Labels:None
-
Environment:Mac OS X 10.5.2, Groovy 1.5.4
-
Number of attachments :
Description
The compiler does not detect unresolved classes under certain conditions. For example, the following script references a type Foo that is unresolved but the compiler does not emit any errors. This code then breaks at runtime.
println Foo.FIELD println Foo.staticMethod()
This is the runtime spew:
Caught: groovy.lang.MissingPropertyException: No such property: Foo for class: unresolved
at unresolved.main(unresolved.groovy)
It would seem that the compiler would know that the type Foo cannot be resolved, as it does in this example, when the unresolved class is referenced as either a static type definition or when attempting to create a new instance:
Foo foo = null // compiler error def var = new Foo() // compiler error
there is without a change to the language no way the compiler could know for sure that Foo is a class in this script. Thus the compiler tests if it is a class at compile time, and if it is not, then the compiler assumes it is some kind of property.. for example a variable from the binding. If you need to be sure that Foo is a certain class, then use an import.