You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Mauro Molinari (JIRA)" <ji...@apache.org> on 2015/07/17 09:14:04 UTC

[jira] [Created] (GROOVY-7507) Cannot assign value of type java.lang.Object in ternary operator with null

Mauro Molinari created GROOVY-7507:
--------------------------------------

             Summary: Cannot assign value of type java.lang.Object in ternary operator with null
                 Key: GROOVY-7507
                 URL: https://issues.apache.org/jira/browse/GROOVY-7507
             Project: Groovy
          Issue Type: Bug
          Components: Static Type Checker
    Affects Versions: 2.4.4, 2.4.3
            Reporter: Mauro Molinari
            Assignee: Cédric Champeau


This seems to be something like a regression of GROOVY-5734.

The following fails in Groovy 2.4.3/2.4.4, while it didn't fail in Groovy 2.3.11:

{code:title=Bar.java}
package test2;

public class Bar {
}
{code}

{code:title=Foo.java}
package test2;

public class Foo {
	private Bar bar;
	
	public void setBar(Bar bar) {
		this.bar = bar;
	}
	
	public Bar getBar() {
		return bar;
	}
}
{code}

{code:title=Test.groovy}
package test2

import groovy.transform.CompileStatic;

@CompileStatic
public class Test {
	void test() {
		boolean check = true
		Foo foo = new Foo()
		foo.bar = check? new Bar(): null
	}
}
{code}

The assignment to {{foo.bar}} fails with:{{Cannot assign value of type java.lang.Object to variable of type test2.Bar}}.

The same heppens if {{Foo}} is written in Groovy instead of Java.



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