You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2022/09/02 18:29:00 UTC

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

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

Eric Milles reassigned GROOVY-7507:
-----------------------------------

    Assignee: Eric Milles

> 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.3, 2.4.4
>            Reporter: Mauro Molinari
>            Assignee: Eric Milles
>            Priority: Major
>
> 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
(v8.20.10#820010)