Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-460

improper parsing behavior or error message

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 1.0-JSR-1
    • 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)

      { println "hello" }

      }

      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!

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            blackdrag Jochen Theodorou
            johnstump John Stump
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment