You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (JIRA)" <ji...@apache.org> on 2019/04/17 19:49:00 UTC

[jira] [Updated] (GROOVY-9089) STC: owner qualifier produces error for nested closures

     [ https://issues.apache.org/jira/browse/GROOVY-9089?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Milles updated GROOVY-9089:
--------------------------------
    Description: 
In the example script below, the use of the "owner" qualifier causes an error.  Replace with "delegate" and no error.  Disable static compilation and no error.

{code:groovy}
class C1 {
  void m() {
    print 'outer delegate'
  }
}
class C2 {
  void m() {
    print 'inner delegate'
  }
}
void outer(@DelegatesTo(value = C1) Closure block) {
  block.delegate = new C1()
  block()
}
void inner(@DelegatesTo(value = C2, strategy = Closure.DELEGATE_FIRST) Closure block) {
  block.delegate = new C2()
  block()
}

@groovy.transform.CompileStatic // comment out and script prints "outer delegate" as expected
void test() {
  outer {
    inner {
      owner.m() // "Cannot find matching method Script#m(). Please check if the declared type is right and if the method exists."
      // replace "owner" with "delegate" and CompileStatic has no error and prints "inner delegate" as expected
    }
  }
}

test()
{code}

  was:
In the example script below, the use of the "owner" qualifier causes an error.  Replace with "delegate" and no error.  Disable static compilation and no error.

{code:groovy}
class C1 {
  void m() {
    print 'outer delegate'
  }
}
class C2 {
  void m() {
    print 'inner delegate'
  }
}
void outer(@DelegatesTo(value = C1) Closure block) {
  block.delegate = new C1()
  block()
}
void inner(@DelegatesTo(value = C2) Closure block) {
  block.delegate = new C2()
  block()
}

@groovy.transform.CompileStatic // comment out and script prints "outer delegate" as expected
void test() {
  outer {
    inner {
      owner.m() // "Cannot find matching method Script#m(). Please check if the declared type is right and if the method exists."
      // replace "owner" with "delegate" and CompileStatic has no error and prints "inner delegate" as expected
    }
  }
}

test()
{code}


> STC: owner qualifier produces error for nested closures
> -------------------------------------------------------
>
>                 Key: GROOVY-9089
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9089
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 3.0.0-alpha-4, 2.5.6
>            Reporter: Eric Milles
>            Priority: Major
>
> In the example script below, the use of the "owner" qualifier causes an error.  Replace with "delegate" and no error.  Disable static compilation and no error.
> {code:groovy}
> class C1 {
>   void m() {
>     print 'outer delegate'
>   }
> }
> class C2 {
>   void m() {
>     print 'inner delegate'
>   }
> }
> void outer(@DelegatesTo(value = C1) Closure block) {
>   block.delegate = new C1()
>   block()
> }
> void inner(@DelegatesTo(value = C2, strategy = Closure.DELEGATE_FIRST) Closure block) {
>   block.delegate = new C2()
>   block()
> }
> @groovy.transform.CompileStatic // comment out and script prints "outer delegate" as expected
> void test() {
>   outer {
>     inner {
>       owner.m() // "Cannot find matching method Script#m(). Please check if the declared type is right and if the method exists."
>       // replace "owner" with "delegate" and CompileStatic has no error and prints "inner delegate" as expected
>     }
>   }
> }
> test()
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)