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 2020/03/09 17:44:00 UTC
[jira] [Commented] (GROOVY-9454) STC: instanceof on generic
property regression
[ https://issues.apache.org/jira/browse/GROOVY-9454?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17055246#comment-17055246 ]
Eric Milles commented on GROOVY-9454:
-------------------------------------
This change for GROOVY-9204 is the cause: 0cb6d88b96871320ec5ece8609cd9437766b71e5
> STC: instanceof on generic property regression
> ----------------------------------------------
>
> 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
>
> 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)