[ 
https://issues.apache.org/jira/browse/GROOVY-10146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17370798#comment-17370798
 ] 

Sterling Greene commented on GROOVY-10146:
------------------------------------------

[~daniel_sun] Thanks for acting on this so quickly!

I'm not sure if your changes completely bring the behavior back to what it was.

I downloaded the nightly built from f3e7b856aad08611cbbd2e477dd879d639d0c379 
and tried the same program and some variations.

The error is definitely better, but it's now identifying the opening quote as 
the source of the problem vs the missing closing quote. I don't have a strong 
feeling if one way is better than the other.

Groovy 2.5 says:
{quote}expecting ''', found '\n' at line: 9, column: 19{quote}
Groovy 3.0.9 nightly says:
{quote}Unexpected character: '\'' at line: 9, column: 13{quote}

The "Unexpected input" message occurs for more than just missing single 
quote/double quotes. e.g., if you try this (missing parenthesis):
{code}
class Foo {
    void bar(Closure c) {
        c.call()
    }
}
def foo = new Foo()

foo.bar {
    println("Hello"
}
{code}

You get...
In Groovy 2.5:
{quote}unexpected token: } at line: 10, column: 1{quote}
In Groovy 3.x:
{quote}Unexpected input: '{' at line: 8, column: 9{quote}

And if you have too many parentheses:
{code}
class Foo {
    void bar(Closure c) {
        c.call()
    }
}
def foo = new Foo()

foo.bar {
    println("Hello"))
}
{code}

You get something similar...
In Groovy 2.5:
{quote}expecting '}', found ')' at line: 9, column: 21{quote}
In Groovy 3.x:
{quote}Unexpected input: '{' at line: 8, column: 9{quote}

I tried this for other things that have opening/closing characters. You get the 
less helpful message for curly braces and square brackets too. 

It gets weirder when the opening curly brace is missing:
{code}
class Foo {
    void bar(Closure c) {
        c.call()
    }
}
def foo = new Foo()

foo.bar {
    if (true) 
        println("Hello")
    }
}
{code}
You get...
In Groovy 2.5:
{quote}unexpected token: } at line: 12, column: 1{quote}
In Groovy 3.x:

{noformat}Unexpected input: '{\n    if (true) \n        println("Hello")\n    
}\n}' at line: 12, column: 1{noformat}

I can split this up into new issues if you would prefer that.  Just let me know.

> Groovy 3 compilation errors are less accurate than Groovy 2
> -----------------------------------------------------------
>
>                 Key: GROOVY-10146
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10146
>             Project: Groovy
>          Issue Type: Improvement
>          Components: Compiler
>    Affects Versions: 3.0.7, 3.0.8
>            Reporter: Sterling Greene
>            Assignee: Daniel Sun
>            Priority: Minor
>             Fix For: 4.0.0-beta-1, 3.0.9
>
>
> Given this broken bit of Groovy code (note the missing single quote after 
> Hello):
> {code:groovy}
> class Foo {
>     void bar(Closure c) {
>         c.call()
>     }
> }
> def foo = new Foo()
> foo.bar {
>     println 'Hello
> }
> {code}
> In Groovy 2.5.11, the compiler generates a message like:
> {quote}expecting ''', found '\n' at line: 10, column: 19{quote}
> In Groovy 3.0.8, the compiler generates a message like:
> {quote}Unexpected input: '{' at line: 9, column: 9{quote}
> 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):
> {code}
> dependencies {
>     testImplementation group: 'junit', name: 'junit', version: '4.12
> }
> {code}
> In Gradle <7 (which uses Groovy 2), the compilation failure says:
> {quote}expecting ''', found '\n' @ line 13, column 69.
>       name: 'junit', version: '4.12{quote}
> But in Gradle 7+ (which uses Groovy 3), the compilation failure says:
> {quote}Unexpected input: '{' @ line 12, column 14.
>      dependencies {{quote}
> 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.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to