Details
-
Bug
-
Status: Closed
-
Blocker
-
Resolution: Fixed
-
2.4.12
-
None
-
Windows 10, Gradle 4.2.1;
IRL @CompileStatic applied via groovyOptions.configurationScript:
withConfig(configuration) { ast(groovy.transform.CompileStatic) }
Description
Below code is a simplification of a Gradle API + Android Gradle Plugin consuming 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() }
Removing <T extends Task> makes it compile, otherwise:
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
So far I haven't found a workaround other than removing generics!