You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2018/04/10 13:03:01 UTC

[jira] [Closed] (GROOVY-8439) @CompileStatic cannot compile generic class's static method

     [ https://issues.apache.org/jira/browse/GROOVY-8439?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul King closed GROOVY-8439.
-----------------------------

> @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, Gradle 4.2.1;
> IRL @CompileStatic applied via groovyOptions.configurationScript:
> withConfig(configuration) { ast(groovy.transform.CompileStatic) }
>            Reporter: Robert Papp
>            Assignee: Daniel Sun
>            Priority: Blocker
>             Fix For: 3.0.0-alpha-2, 2.5.0-rc-1, 2.4.15, 2.6.0-alpha-4
>
>
> 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
(v7.6.3#76005)