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

Groovy 3 compilation errors are less accurate than Groovy 2

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.0.7, 3.0.8
    • Fix Version/s: 4.0.0-beta-1, 3.0.9
    • Component/s: Compiler
    • Labels:
      None

      Description

      Given this broken bit of Groovy code (note the missing single quote after Hello):

      class Foo {
          void bar(Closure c) {
              c.call()
          }
      }
      def foo = new Foo()
      
      foo.bar {
          println 'Hello
      }
      

      In Groovy 2.5.11, the compiler generates a message like:

      expecting ''', found '\n' at line: 10, column: 19

      In Groovy 3.0.8, the compiler generates a message like:

      Unexpected input: '{' at line: 9, column: 9

      The Groovy 2.x message has identified the right problem (a missing single quote), while the Groovy 3.x message is unrelated to the syntax error.

      We see this in Gradle build scripts too. In this broken Gradle script (again, a missing single quote):

      dependencies {
          testImplementation group: 'junit', name: 'junit', version: '4.12
      }
      

      In Gradle <7 (which uses Groovy 2), the compilation failure says:

      expecting ''', found '\n' @ line 13, column 69.
      name: 'junit', version: '4.12

      But in Gradle 7+ (which uses Groovy 3), the compilation failure says:

      Unexpected input: '{' @ line 12, column 14.
      dependencies {

      I assume this effects all Groovy 3.x versions, but I only tried 3.0.7 and 3.0.8. I also assume the better behavior is the same for all Groovy 2.x, but I didn't try any other version.

        Attachments

          Activity

            People

            • Assignee:
              daniel_sun Daniel Sun
              Reporter:
              big-guy Sterling Greene
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: