groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cédric Champeau (JIRA) <j...@apache.org>
Subject [jira] [Commented] (GROOVY-8355) Instanceof inference does not work on field assigning
Date Wed, 18 Oct 2017 08:45:00 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-8355?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16208986#comment-16208986
] 

Cédric Champeau commented on GROOVY-8355:
-----------------------------------------

This works as expected. You cannot compare the two situations as they are very different.
In one case, there's an explicit intent, expressed by an `instanceof` check. We are _trusting_
the user here. It's a big difference between inferring and trusting. If the user says "believe
me, here it's a String", and "I am inferring that this is a String". If the user is wrong,
there's going to be a runtime error, but we shouldn't prevent them from doing what they think
is right. It's not different from plain Java.

> Instanceof inference does not work on field assigning
> -----------------------------------------------------
>
>                 Key: GROOVY-8355
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8355
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation, Static Type Checker
>            Reporter: Alexey Afanasiev
>
> If instanceof inference works as expected [https://issues.apache.org/jira/browse/GROOVY-8293]
So probably this code should work to:
> {code}
> import groovy.transform.CompileStatic
> @CompileStatic
> class Foo {
>     Object str = new Object()
>     def bar() {
>         str = "str"
>         str.toUpperCase() // here compile error
>     }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message