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

@DelegatesTo: static type checker misses an error

    Details

      Description

      Consider the following example:

      def with(@DelegatesTo.Target Object target, @DelegatesTo(strategy = Closure.DELEGATE_FIRST) Closure arg) {
          arg.delegate = target
          arg.setResolveStrategy(Closure.DELEGATE_FIRST)
          arg()
      }
      
      @CompileStatic
      def test() {
          def obj = [1, 2]
          with(obj, {
              print(last()) //error is here
          },)
      }
      
      test()
      

      last() is DGM for List.

      There is two ways to resolve the issue:
      1. resolve 'last()' to 'obj.last()'. So the code will work
      2. register an error if you think that injected methods should not be resolved in 'DelegatesTo' context

        Attachments

          Activity

            People

            • Assignee:
              melix Cédric Champeau
              Reporter:
              mxm-groovy Maxim Medvedev
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: