You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Stefan Wolf (JIRA)" <ji...@apache.org> on 2016/07/20 11:14:20 UTC
[jira] [Updated] (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:all-tabpanel ]
Stefan Wolf updated GROOVY-7888:
--------------------------------
Description:
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}
was:
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 works, too:
{code}
class ContainsSet {
Set<File> files = new HashSet<>()
}
{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)