Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Braces not correctly matched in Groovy due to closures #139

Closed
Mahesha999 opened this issue Sep 10, 2015 · 1 comment
Closed

Braces not correctly matched in Groovy due to closures #139

Mahesha999 opened this issue Sep 10, 2015 · 1 comment

Comments

@Mahesha999
Copy link

I have Eclipse Luna (Service Release 1a (4.4.1)) with following plugins installed:

Groovy-Eclipse Feature
Groovy Compiler 2.0 Feature 2.9.1.xx-201412191752-e44
Grails IDE 3.6.3.201411271013-RELEASE

I have a simple class:

class Utilities 
{
    public static boolean hasValue(List list){
        return !(list == null || list.isEmpty());
    }
}

Another simple class:

class Test2 {        
    static main(def args)
    {
        def var1 = [2]        
        if(Utilities.hasValue((List)var1)  //here one bracket is less but still compiler does not give any error
        {
            println "hello"               
        }
    }
}

It is only when I run Test2, it gives me following exception:

No signature of method: static Utilities.hasValue() is applicable for argument types: (java.util.ArrayList, Test2$_main_closure1)

Also when I add another if() to Test2, then it gives not much sensing error description:

class Test2 {        
    static main(def args)
    {
        def var1 = [2]        
        if(Utilities.hasValue((List)var1)  
        {
            println "hello"               
        }
        if(true) { }  //Groovy:Expecting '}', found 'if'
    }
}

I tried same in Groovy/Grails Tool Suite (which is also eclipse based) by GoPivotal v 3.3.0.RELEASE. It also gives same error.

@doktorjw
Copy link

doktorjw commented Jan 5, 2016

For some reason, the compiler isn't picking up that the parenthesis are mismatched in your source (the line ... if(Utilities.hasValue(... is missing a closing paren. Without the paren, it's possible the code block for the if is being interpreted as a closure ... and the extra if throws enough additional code into the mix that syntax errors are finally recognized. Strange that it initially passed code validation (after running it, I removed the paren that I had added, and eclipse properly identified a syntax error in the code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants