You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "John Wagenleitner (JIRA)" <ji...@apache.org> on 2018/06/12 17:51:00 UTC

[jira] [Commented] (GROOVY-8640) Cannot find matching comparator method

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

John Wagenleitner commented on GROOVY-8640:
-------------------------------------------

I believe this is related to GROOVY-8562. Inside that closure {{this}} would refer to {{Test.Nested}} and it does have a {{MAX_LINES}} property because of the delegate. If you remove {{CompileStatic}} you would see that {{MAX_LINES}} resolves to {{NULL}} which dynamic groovy handles as 0. So I think this error is correct and the fix would be to use {{Test.MAX_LINES}} inside the closure instead of the implicit {{this.MAX_LINES}}.

> Cannot find matching comparator method
> --------------------------------------
>
>                 Key: GROOVY-8640
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8640
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.5.0
>            Reporter: paolo di tommaso
>            Priority: Minor
>
> The following class static compilation fails
> {code:java}
> @CompileStatic
> class Test  {
>     static private int MAX_LINES = 100
>     private static class Nested  {
>         @Delegate
>         private Map<String,Object> delegate = [:]
>         private String fetch(Path path) {
>             int c=0
>             def result = new StringBuilder()
>             path.withReader { reader ->
>                 String line
>                 while( (line=reader.readLine()) && c++<MAX_LINES ) {
>                     result << line
>                 }
>             }
>             result
>         }
>     }
> }{code}
>  
> Reported error: 
> {code:java}
> Test.groovy: 45: [Static type checking] - Cannot find matching method java.lang.Integer#compareTo(java.lang.Object). Please check if the declared type is correct and if the method exists.
> @ line 45, column 55.
>    line=reader.readLine()) && c++<MAX_LINES
>                                  ^{code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)