Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
-
None
-
None
-
mac os x 10.3.3, java 1.4.2
Description
This bug had me scratching my head for a looong time. Here is a sample class that this happens:
Class Bug5 {
static void main(args)
}
The error I get is:
Caught: Bug5.groovy: 2: could not use 'static' at 2:5
Bug5.groovy: 2: could not use 'static' at 2:5
Bug5.groovy: 5: could not use '}' at 5:1
at org.codehaus.groovy.control.ProcessingUnit.fail(ProcessingUnit.java:466)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:877)
at org.codehaus.groovy.control.CompilationUnit.parse(CompilationUnit.java:508)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:470)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:228)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:154)
at groovy.lang.GroovyShell$2.run(GroovyShell.java:207)
(etc)
For the sharp-eyed people, you will notice that instead of "class" I errantly did "Class". So I guess the parser is trying to declare a variable named Bug5 of type Class, but I don't understand why it allows the chunk of code in the braces. I thought valid variable declarations looked like this:
[<type>] <name> [= <value>]
Anyway, if this is valid syntax, may I request that the error message be a little more descriptive, like "static is not allowed in a field initialization block" or something like that? That would have at least clued me into that the parser thinks he's doing something different than what I was intending to do, and make my debugging a little quicker.
Thanks!