You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2020/07/23 14:17:05 UTC

[jira] [Closed] (GROOVY-9591) Compiler error for use of variable expression within tap closure

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

Paul King closed GROOVY-9591.
-----------------------------

> Compiler error for use of variable expression within tap closure
> ----------------------------------------------------------------
>
>                 Key: GROOVY-9591
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9591
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 3.0.4, 2.5.12
>            Reporter: Eric Milles
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-alpha-1, 3.0.5
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> Consider the following:
> {code:groovy}
> @groovy.transform.ToString
> class A {
>   A(a) {}
>   def b
> }
> class C {
>   C() {
>     this(new A(null).tap { b = 42 })
>   }
> C(x) {
>     print x
>   }
> }
> new C() // should output "A(42)"
> {code}
> A has no default constructor, so properties are initialized in tap closure.  Because the "tap" expression is passed as argument to special constructor call, extra static checking is performed and the error "Apparent variable 'b' was found in a static scope but doesn't refer to a local variable, static field or class." is emitted.
> Creation of A cannot be moved to a local variable because special constructor call must be the first statement/expression in the constructor body.
> This was discovered while investigating variations of GROOVY-8327, GROOVY-8389, and GROOVY-9587. 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)