Robert Papp created GROOVY-8439:
-----------------------------------

             Summary: @CompileStatic cannot compile generic class's static 
method
                 Key: GROOVY-8439
                 URL: https://issues.apache.org/jira/browse/GROOVY-8439
             Project: Groovy
          Issue Type: Bug
          Components: Static compilation
    Affects Versions: 2.4.12
         Environment: Windows 10, IRL @CompileStatic applied via 
groovyOptions.configurationScript:
withConfig(configuration) { ast(groovy.transform.CompileStatic) }
            Reporter: Robert Papp
            Priority: Blocker


Below code is a simplification of a Gradle API + Android Gradle Plugin 
consuming code:
{code}
@CompileStatic
class Test<T extends Task> {

        static def something(Task task, Collection<BaseVariant> variants) {
                variants
                                .collectMany {it.sourceFolders}
                                .collect {ConfigurableFileTree tree ->
                        
task.buildDir.toPath().relativize(tree.dir.toPath()).toString() + File.separator
                }
        }
}

interface BaseVariant {

        List<ConfigurableFileTree> getSourceFolders()
}

interface ConfigurableFileTree {

        File getDir()
}

interface Task {

        File getBuildDir()
}
{code}

Removing {{<T extends Task>}} makes it compile, otherwise:
{code}

test\src\main\groovy\Test.groovy: 8: Expected parameter of type Task but got 
ConfigurableFileTree
 @ line 8, column 15.
                                .collect {ConfigurableFileTree tree ->
                 ^

test\src\main\groovy\Test.groovy: 9: [Static type checking] - No such property: 
dir for class: Task
 @ line 9, column 38.
                        
task.buildDir.toPath().relativize(tree.dir.toPath()).toString() + File.separator
                                        ^

test\src\main\groovy\Test.groovy: 9: [Static type checking] - Cannot find 
matching method java.nio.file.Path#relativize(java.lang.Object). Please check 
if the declared type is right and if the method exists.
 @ line 9, column 4.
                        
task.buildDir.toPath().relativize(tree.dir.toPath()).toString() + File.separator
      ^

3 errors

:checkstyle:compileGroovy FAILED
{code}

So far I haven't found a workaround other than removing generics!



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to