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 2021/03/02 16:54:00 UTC
[jira] [Updated] (GROOVY-9907) Type tracked from instanceof
condition is not captured in closure
[ https://issues.apache.org/jira/browse/GROOVY-9907?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles updated GROOVY-9907:
--------------------------------
Fix Version/s: 3.0.8
> Type tracked from instanceof condition is not captured in closure
> -----------------------------------------------------------------
>
> Key: GROOVY-9907
> URL: https://issues.apache.org/jira/browse/GROOVY-9907
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation
> Affects Versions: 3.0.7
> Reporter: Thodoris Sotiropoulos
> Assignee: Eric Milles
> Priority: Major
> Fix For: 3.0.8, 4.0.0-alpha-3
>
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> I have the following Groovy program
>
>
> {code:java}
> @groovy.transform.TypeChecked
> class Test {
> public static void main(String[] args) {
> println(foo(10));
> }
> static Integer foo(Object x) {
> if (x instanceof Integer) {
> def bar = {x};
> return bar();
> }
> return 100;
>
> }
> }
> {code}
>
>
> h2. Actual Behavior
> The program does not compile, and I get the following error
>
> {code:java}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> program.groovy: 10: [Static type checking] - Cannot return value of type java.lang.Object on method returning type java.lang.Integer
> @ line 10, column 14.
> return bar();
> ^1 error
> {code}
> h2. Expected Behavior
> Compile successfully.
> In particular I would expect that the inferred type of the return type of closure is "Integer" and not "Object", as the closure is defined inside a block where the following condition holds.
> {code:java}
> x instanceof Integer
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)