groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul King (JIRA)" <j...@apache.org>
Subject [jira] [Closed] (GROOVY-7713) CompileStatic checking fails with null returns
Date Wed, 01 Feb 2017 23:19:01 GMT

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

Paul King closed GROOVY-7713.
-----------------------------

> CompileStatic checking fails with null returns
> ----------------------------------------------
>
>                 Key: GROOVY-7713
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7713
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 2.4.4, 2.4.5
>            Reporter: Scott Douglas
>            Assignee: John Wagenleitner
>            Priority: Minor
>             Fix For: 2.4.8
>
>         Attachments: Test1.groovy, Test2.groovy, Test3.groovy, Test4.groovy
>
>
> ---------
> TEST 1
> ---------
> {code}
> package test
> import groovy.transform.CompileStatic
> class TestClass {
> 	@CompileStatic
> 	void doTest() {
> 		Closure<String> closure = {
> 			return "foo";
> 		}
> 	}
> }
> {code}
> Compiles fine.
> ---------
> TEST 2
> ---------
> {code}
> package test
> import groovy.transform.CompileStatic
> class TestClass {
> 	@CompileStatic
> 	void doTest() {
> 		Closure<String> closure = {
> 			if ("bah".length() == 3) {
> 				return null
> 			}
> 			return "foo";
> 		}
> 	}
> }
> {code}
> ...gives...
> {code}
> groovyc Test2.groovy
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> Test2.groovy: 9: [Static type checking] - Incompatible generic argument types. Cannot
assign groovy.lang.Closure <java.lang.Object> to: groovy.lang.Closure <String>
>  @ line 9, column 29.
>    		Closure<String> closure = {
>                                ^
> 1 error
> {code}
> ---------
> TEST 3
> ---------
> {code}
> package test
> import groovy.transform.CompileStatic
> class TestClass {
> 	@CompileStatic
> 	void doTest() {
> 		Closure<String> closure = {
> 			return null;
> 		}
> 	}
> }
> {code}
> ...gives...
> {code}
> groovyc Test3.groovy
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> Test3.groovy: 9: [Static type checking] - Incompatible generic argument types. Cannot
assign groovy.lang.Closure <java.lang.Object> to: groovy.lang.Closure <String>
>  @ line 9, column 29.
>    		Closure<String> closure = {
>                                ^
> 1 error
> {code}
> ---------
> TEST 4
> ---------
> {code}
> package test
> import groovy.transform.CompileStatic
> class TestClass {
> 	@CompileStatic
> 	void doTest() {
> 		Closure<String> closure = {
> 		}
> 	}
> }
> {code}
> Compiles fine.
> ---------
> COMMENTS
> ---------
> All files were compiled with 'groovyc Test\[1234\].groovy'. I expected all tests to compile.
I wouldn't have thought returning null would cause a static compilation failure since null
is a valid String. Also, I expected test 3 and test 4 to be equivalent.
> The workaround appears to be to cast the closure, like:
> {code}
> Closure<String> closure = (Closure<String>) {
>     ...
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message