Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-6600

Compilation error when creating an anonymous subclass of a class implementing propertyMissing setter

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.1.9, 2.2.2, 2.4.0-rc-1
    • None
    • class generator, Compiler
    • None
    • Ubuntu Linux
      Oracle JDK 1.7.0_45 64-bit
      Groovy 2.2.2
      Groovy 2.1.9

    Description

      Creating an anonymous subclass of class that implements a propertyMissing setter with return type of "def" results in a compilation error:

      // 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(){}
      

      The compilation error is as follows:

      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
      

      Declaring and instantiating a named subclass of FooA produces no errors.

      // This code works.
      class FooB extends FooA {}
      def namedSubclass = new FooB()
      

      As a workaround, the propertyMissing setter can be declared with a "void" return type.

      // This code works
      class FooC {    
          Map m = [:]
          void propertyMissing(String name, def value) { m[name] = value }
      }
      
      def anonSubclass2 = new FooC(){}
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            citizenkoen Christopher Koenig
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: