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

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.1.9, 2.2.2, 2.4.0-rc-1
    • Fix Version/s: None
    • Component/s: class generator, Compiler
    • Labels:
      None
    • Environment:
      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

            • Assignee:
              Unassigned
              Reporter:
              citizenkoen Christopher Koenig
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: