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 2017/02/01 23:19:06 UTC

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

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

Paul King closed GROOVY-7888.
-----------------------------

> 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
>            Assignee: Paul King
>             Fix For: 2.4.8
>
>
> 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.15#6346)