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 2023/05/04 17:55:00 UTC

[jira] [Created] (GROOVY-11044) SC: property write within closure produces cast exception

Eric Milles created GROOVY-11044:
------------------------------------

             Summary: SC: property write within closure produces cast exception
                 Key: GROOVY-11044
                 URL: https://issues.apache.org/jira/browse/GROOVY-11044
             Project: Groovy
          Issue Type: Bug
          Components: Static compilation
    Affects Versions: 4.0.12
            Reporter: Eric Milles
            Assignee: Eric Milles


Consider the following:
{code:groovy}
class Bar {
  @groovy.beans.Bindable
  String baz
  String other
}
class Foo {
  Bar bar
  @groovy.beans.Bindable
  String foo
  @groovy.transform.CompileStatic
  void postConstruct() {
    bar = new Bar()
    bar.with {
      addPropertyChangeListener('baz') { event ->
        other = 'value' // ClassCastException: class Foo cannot be cast to class Bar
        print 'changed'
      }
    }
    print 'ready;'
  }
}

Foo foo = new Foo()
foo.postConstruct()
foo.getBar().setBaz('xxx')
{code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)