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/07/23 16:32:00 UTC

[jira] [Updated] (GROOVY-10667) Wrong Type-Inference in `instanceof` block

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

Eric Milles updated GROOVY-10667:
---------------------------------
    Fix Version/s:     (was: 5.0.0-alpha-1)

> Wrong Type-Inference in `instanceof` block
> ------------------------------------------
>
>                 Key: GROOVY-10667
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10667
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 4.0.3
>         Environment: I tried Java 8 and 17. Both from a Gradle 7.1 project.
>            Reporter: Jan Hackel
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.4
>
>
> Groovy 4.0.3 produces the error
> {{[Static type checking] - Cannot find matching method de.jhunovis.instance_of.MethodArgumentTypeInferenceErrorTest#doSomethingWithException(de.jhunovis.instance_of.MethodArgumentTypeInferenceErrorTest$Tagged). Please check if the declared type is correct and if the method exists.}}
> for this piece of code:
> {code:groovy}
> import groovy.transform.CompileStatic
> @CompileStatic
> class MethodArgumentTypeInferenceErrorTest {
>   private static interface Tagged {
>     String getTag()
>   }
>   private static class TaggedException extends RuntimeException implements Tagged {
>     String tag
>   }
>   void cannotFindMatchingMethod() {
>     doSomethingWith(new TaggedException(tag: 'Test'))
>   }
>   private static void doSomethingWith(Exception e) {
>     if (e instanceof Tagged) {
>       println e.tag
>       doSomethingWithException(e)
>     }
>   }
>   private static void doSomethingWithException(Exception exception) {
>   }
> }
> {code}
> It seems the `instanceof` confuses the type-inference.



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