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 2023/02/10 21:41:00 UTC

[jira] [Closed] (GROOVY-10356) STC changes the inferred type of variable in the presence of flow typing

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

Paul King closed GROOVY-10356.
------------------------------

> STC changes the inferred type of variable in the presence of flow typing
> ------------------------------------------------------------------------
>
>                 Key: GROOVY-10356
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10356
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Thodoris Sotiropoulos
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.5
>
>
> This may be related to GROOVY-10294.
> I have the following program
> {code:java}
> interface A {
>   void a();
> }
> class Test {
>   void test_closure() {
>     def a = (A) null;
>     def x = { ->
>       a = null;
>     }
>     a.a();
>   }
> }
> {code}
> h3. Actual behaviour
> {code}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> test.groovy: 15: [Static type checking] - A closure shared variable [a] has been assigned with various types and the method [a()] does not exist in the lowest upper bound of those types: [java.lang.Object]. In general, this is a bad practice (variable reuse) because the compiler cannot determine safely what is the type of the variable at the moment of the call in a multithreaded context.
>  @ line 15, column 5.
>        a.a();
>        ^
> 1 error
> {code}
> h3. Expected behaviour
> Compile successfully
> Tested against master (https://github.com/apache/groovy/commit/0ff632514f9e06b8cea96f2e70749b3da3bc6dbb).



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