[
https://issues.apache.org/jira/browse/GROOVY-6600?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Eric Milles reassigned GROOVY-6600:
-----------------------------------
Assignee: Eric Milles
> Compilation error when creating an anonymous subclass of a class implementing
> propertyMissing setter
> ----------------------------------------------------------------------------------------------------
>
> Key: GROOVY-6600
> URL: https://issues.apache.org/jira/browse/GROOVY-6600
> Project: Groovy
> Issue Type: Bug
> Components: class generator, Compiler
> Affects Versions: 2.1.9, 2.2.2, 2.4.0-rc-1
> Environment: Ubuntu Linux
> Oracle JDK 1.7.0_45 64-bit
> Groovy 2.2.2
> Groovy 2.1.9
> Reporter: Christopher Koenig
> Assignee: Eric Milles
> Priority: Major
> Fix For: 4.0.30, 5.0.4
>
>
> Creating an anonymous subclass of class that implements a propertyMissing
> setter with return type of "def" results in a compilation error:
> {code:java}
> // This code does not work
> class FooA {
> Map m = [:]
> def propertyMissing(String name, def value) { m[name] = value }
> }
> // This statement produces a compilation error
> def anonSubclass = new FooA(){}
> {code}
> The compilation error is as follows:
> {noformat}
> 1 compilation error:
> The return type of void propertyMissing(java.lang.String, java.lang.Object)
> in ConsoleScript7$1 is incompatible with java.lang.Object
> propertyMissing(java.lang.String, java.lang.Object) in FooA
> . At [-1:-1] at line: -1, column: -1
> {noformat}
> Declaring and instantiating a named subclass of FooA produces no errors.
> {code:java}
> // This code works.
> class FooB extends FooA {}
> def namedSubclass = new FooB()
> {code}
> As a workaround, the propertyMissing setter can be declared with a "void"
> return type.
> {code:java}
> // This code works
> class FooC {
> Map m = [:]
> void propertyMissing(String name, def value) { m[name] = value }
> }
> def anonSubclass2 = new FooC(){}
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)