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-8293) Instanceof inference does work on fields
Date Tue, 22 Aug 2017 07:52:00 GMT

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

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

It works as expected. The fact that Groovy doesn't infer the type of the field from its declaration
doesn't prevent the compiler from doing smarts, especially the _instanceof_ check. You're
telling it that the type is a String, so it complies.

> Instanceof inference does work on fields
> ----------------------------------------
>
>                 Key: GROOVY-8293
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8293
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation, Static Type Checker
>    Affects Versions: 2.4.12
>            Reporter: Alexey Afanasiev
>
> This code should not compile:
> {code}
> import groovy.transform.CompileStatic
> @CompileStatic
> class Foo {
>     Object str = "str"
>     def bar() {
>         if (str instanceof String) {
>             str.toUpperCase() // here should be compile error
>         }
>     }
> }
> {code}
> Documentation http://docs.groovy-lang.org/next/html/documentation/core-semantics.html#type-inference
states: 
> _it does not perform any kind of type inference on fields, always falling back to the
declared type of a field_



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

Mime
View raw message