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

Closure resolve strategy DELEGATE_FIRST and DELEGATE_ONLY behave oddly when delegate is set

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • None
    • None
    • None
    • None

    Description

      The sample below outputs "value" as is. When cl.resolveStrategy = Closure.DELEGATE_FIRST is added before cl(), it outputs "null" when I would expect "value" since that's available from owner. When cl.resolveStrategy = Closure.DELEGATE_ONLY is added instead, it outputs "null" when I would expect a missing property exception.

      class Test {
        def prop = 'value'
        def meth() {
          def cl = { -> println prop }
          cl.delegate = [:]
          cl()
        }
      }
      new Test().meth()
      

      This was run using Groovy Web Console.

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            emilles Eric Milles
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: