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

Incorrect property lookup if a method starts with "get"

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 2.1.4
    • None
    • None

    Description

      import groovy.transform.*
      
      @TupleConstructor
      class Person { String name }
      
      public <T> List<T> names(
          @DelegatesTo.Target List<T> list, 
          @DelegatesTo(genericTypeIndex = 0) Closure modify) {
              list.collect {
                  modify.delegate = it
                  modify()
              }
      }
      
      @CompileStatic
      def test(List<Person> persons) {
          def names = names(persons) {
              getname().toUpperCase()
          }
          assert names == ['GUILLAUME', 'CÉDRIC']
      }
      
      test([new Person('Guillaume'), new Person('Cédric')])
      

      If I make a typo in getName() method like above, I get a runtime error instead of getting a type checker compile-time error.

      Attachments

        Activity

          People

            melix Cédric Champeau
            guillaume Guillaume Sauthier
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: