You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2022/11/01 16:41:00 UTC

[jira] [Updated] (GROOVY-7141) Static type checker does not recognize closure input parameter when implementing an interface with a map

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

Eric Milles updated GROOVY-7141:
--------------------------------
    Fix Version/s: 4.0.7

> Static type checker does not recognize closure input parameter when implementing an interface with a map
> --------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-7141
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7141
>             Project: Groovy
>          Issue Type: Improvement
>          Components: Static Type Checker
>    Affects Versions: 2.3.7
>            Reporter: Mauro Molinari
>            Assignee: Eric Milles
>            Priority: Minor
>             Fix For: 4.0.7
>
>
> Consider the following Groovy class:
> {code}
> package e
> import groovy.transform.TypeChecked;
> @TypeChecked
> class E {
> 	
> 	interface MyInt {
> 		String doSomething(String text)
> 	}
> 	
> 	static void main(String[] args) {
> 		MyInt impl = [
> 			doSomething: { it.toUpperCase() }
> 			] as MyInt
> 		println impl.doSomething('foo')
> 	}
> }
> {code}
> The compiler complains that:
> {noformat}
> Groovy:[Static type checking] - Cannot find matching method java.lang.Object#toUpperCase(). Please check if 
>  the declared type is right and if the method exists.
> {noformat}
> However I think Groovy should be smart enough to recognize that {{it}} is of type {{String}} inside the closure.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)