Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
3.0.4, 2.5.12
-
None
-
None
Description
Consider the following:
@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)"
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.