[ https://issues.apache.org/jira/browse/GROOVY-8459?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles updated GROOVY-8459: -------------------------------- Description: Hi, In following method overloading code, a closure with return value are coerced to type Runnable, whose only method returns void. I think a compile warning or error should be issued here. {code:groovy} import java.util.concurrent.Callable class Foo { def <T> void foo(Callable<T> c) { println "Callable foo" } void foo(Runnable r) { println "Runnable foo" } def test() { // ---> BOTH foo()s are resolved to foo(Runnable) overload version, followed closures coerced to Runnable, dispite the fact that the 1st closure has return value. foo { return 1 // Runnable's single method return type is void, should not match this closure with return value. } foo { } } static void main(String[] args) { new Foo().test() } } {code} was: Hi, In following method overloading code, a closure with return value are coerced to type Runnable, whose only method returns void. I think a compile warning or error should be issued here. {code:groovy} class Foo { def <T> void foo(Callable<T> c) { println "Callable foo" } void foo(Runnable r) { println "Runnable foo" } def test() { // ---> BOTH foo()s are resolved to foo(Runnable) overload version, followed closures coerced to Runnable, dispite the fact that the 1st closure has return value. foo { return 1 // Runnable's single method return type is void, should not match this closure with return value. } foo { } } static void main(String[] args) { new Foo().test() } } {code} > Closure with return value coercion problem in overloaded methods > ---------------------------------------------------------------- > > Key: GROOVY-8459 > URL: https://issues.apache.org/jira/browse/GROOVY-8459 > Project: Groovy > Issue Type: Bug > Components: Compiler > Affects Versions: 2.4.13 > Reporter: Evermind > Priority: Minor > > Hi, > In following method overloading code, a closure with return value are > coerced to type Runnable, whose only method returns void. I think a compile > warning or error should be issued here. > {code:groovy} > import java.util.concurrent.Callable > class Foo { > def <T> void foo(Callable<T> c) { > println "Callable foo" > } > void foo(Runnable r) { > println "Runnable foo" > } > def test() { > // ---> BOTH foo()s are resolved to foo(Runnable) overload version, > followed closures coerced to Runnable, dispite the fact that the 1st closure > has return value. > foo { > return 1 // Runnable's single method return type is void, > should not match this closure with return value. > } > foo { > } > } > static void main(String[] args) { > new Foo().test() > } > } > {code} -- This message was sent by Atlassian Jira (v8.20.10#820010)