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 2020/11/11 02:02:05 UTC

[jira] [Closed] (GROOVY-9454) STC: regression for instanceof on generic field/property

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

Paul King closed GROOVY-9454.
-----------------------------

> STC: regression for instanceof on generic field/property
> --------------------------------------------------------
>
>                 Key: GROOVY-9454
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9454
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 3.0.0, 2.5.10, 3.0.1, 3.0.2
>            Reporter: Eric Milles
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-alpha-1, 3.0.3, 2.5.14
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> Consider the following:
> {code:groovy}
> interface Face {
> }
> class Impl implements Face {
>     String something
> }
> @groovy.transform.CompileStatic // or TypeChecked
> class Task<R extends Face> implements java.util.concurrent.Callable<String> {
>     R request
>     @Override
>     String call() {
>         if (request instanceof Impl) {
>             def thing = request.something // No such property: something for class: R
>             def lower = thing.toLowerCase()
>         } else {
>             // ...
>             return null
>         }
>     }
> }
> def task = new Task<Impl>(request: new Impl(something: 'Hello World'))
> assert task.call() == 'hello world'
> {code}
> Groovy 2.5.9 had flow-type support for "instanceof Impl", so no compiler error for "request.something" (which comes from Impl).  This also affects Groovy 3, so I think the recent generics backport has something to do with it.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)