Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.1.6
-
None
Description
import groovy.transform.CompileStatic interface Bar { String getField() } class BarImpl implements Bar { String field } class Foo { Bar bar Foo(String field) { this.bar = new BarImpl(field: field) } } @CompileStatic class Tester { void test() { Foo foo = new Foo('value') println foo.bar.with { "$field" } } } new Tester().test()
when compiled with groovyc results in the following compilation error:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
bad.groovy: 23: [Static type checking] - The variable [field] is undeclared.
@ line 23, column 28.
println foo.bar.with { "$field" }
^
1 error
However, without the @CompileStatic on the Tester class, the code compiles cleanly and runs successfully.
From what I've been able to discern, the compilation error does not occur if the with() occurs on the 'top-level' object and only occurs when the contained/subordinate object is an interface.