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 2020/07/23 14:17:06 UTC
[jira] [Closed] (GROOVY-9597) CompileStatic: @ClosureParams in
@DelegatesTo doesn't work
[ https://issues.apache.org/jira/browse/GROOVY-9597?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King closed GROOVY-9597.
-----------------------------
> CompileStatic: @ClosureParams in @DelegatesTo doesn't work
> ----------------------------------------------------------
>
> Key: GROOVY-9597
> URL: https://issues.apache.org/jira/browse/GROOVY-9597
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Affects Versions: 3.0.4
> Environment: Tested in GroovyConsole 3.0.4
> Reporter: Felix Scheinost
> Assignee: Eric Milles
> Priority: Minor
> Fix For: 4.0.0-alpha-1, 3.0.5, 2.5.13
>
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> This code doesn't compile with this error:
> {noformat}
> [Static type checking] - Cannot find matching method java.lang.Object#toBigDecimal(). Please check if the declared type is correct and if the method exists.{noformat}
> Explicitly adding a `delegate.someFunctionName` works around the problem.
> {code:groovy}
> import groovy.transform.CompileStatic
> import groovy.transform.stc.ClosureParams
> import groovy.transform.stc.FirstParam
> import groovy.transform.stc.FromString
> @CompileStatic
> class Delegate {
> def <T2> void someFunctionName(Collection<T2> values, @ClosureParams(FirstParam.FirstGenericType) Closure<String> optionKey) {
> }
> static Delegate of(@DelegatesTo(Delegate) Closure c) {
> def d = new Delegate()
> c.delegate = d
> c()
> return d
> }
> }
> @CompileStatic
> class App {
> List<Integer> someList
> Delegate datePicker = Delegate.of {
> someFunctionName(
> this.someList,
> // Here: Cannot find matching method java.lang.Object#toBigDecimal(). Please check if the declared type is correct and if the method exists.
> // But it should be known to be Integer
> // The code compiles when delegate.someFunctionName is used above
> { it.toBigDecimal().toString() },
> )
> }
> }
> new App()
> {code}
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)