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 2016/07/22 06:31:20 UTC
[jira] [Commented] (GROOVY-7888) Type checker infers wrong type
collection plus assignment (+=) for property on Java class
[ https://issues.apache.org/jira/browse/GROOVY-7888?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15388997#comment-15388997 ]
Paul King commented on GROOVY-7888:
-----------------------------------
The long-hand version is correctly handled too:
{code}
set.files = set.files + new File('foo')
{code}
> Type checker infers wrong type collection plus assignment (+=) for property on Java class
> -----------------------------------------------------------------------------------------
>
> 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)