groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-7888) Type checker infers wrong type on compound assignment (e.g. += for collection) for property
Date Mon, 22 Aug 2016 06:58:20 GMT

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

ASF GitHub Bot commented on GROOVY-7888:
----------------------------------------

GitHub user paulk-asert opened a pull request:

    https://github.com/apache/groovy/pull/390

    GROOVY-7888: Type checker infers wrong type on compound assignment (e…

    ….g. += for collection) for property

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/paulk-asert/groovy groovy7888

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/groovy/pull/390.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #390
    
----
commit c6aacaf01a347504422abc5d3567b758aab5ef84
Author: paulk <paulk@asert.com.au>
Date:   2016-08-22T06:53:25Z

    GROOVY-7888: Type checker infers wrong type on compound assignment (e.g. += for collection)
for property

----


> Type checker infers wrong type on compound assignment (e.g. += for collection) for property
> -------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-7888
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7888
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 2.4.7
>            Reporter: Stefan Wolf
>
> Given the Java class
> {code}
> public class ContainsSet extends GroovyObjectSupport {
>     private Set<File> files = new HashSet<File>();
>     public Set<File> getFiles() {
>         return files;
>     }
>     public void setFiles(Set<File> files) {
>         this.files = files;
>     }
> }
> {code}
> the following Groovy code will not type check:
> {code}
> @TypeChecked
> private Set<File> modifyIdeaModel() {
>     set.files += new File('foo')
> }
> {code}
> The failure is: 
> {code}
> Error: Groovyc: [Static type checking] - Cannot assign value of type java.io.File to
variable of type java.util.Set <java.io.File>
> {code}
> Without the {{@TypeChecked}} the code runs with dynamic Groovy.
> Using the following Groovy class type checking the code above works.
> {code}
> class ContainsSet {
>     Set<File> files = new HashSet<>()
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message