codeconsole opened a new pull request, #3107:
URL: https://github.com/apache/groovy/pull/3107
`{ log << new StringBuilder('a').with { append('b') }.toString() }` in a
`@CompileStatic` class now works, as it did in 4.0. Before, it failed with
`IncompatibleClassChangeError: Class java.lang.StringBuilder does not implement
the requested interface groovy.lang.GroovyObject` for any delegate that is not
a Groovy object.
The type checker records when an implicit-this call in a closure goes to the
delegate, and the static invocation writer then replaces the receiver with
`this.delegate`, but kept the call adapter chosen for a call on `this`. The
instance initializer blocks of a `@CompileStatic` class are type checked, but
their calls get no method targets, so the call was made dynamically with
`ScriptBytecodeAdapter.invokeMethodOnCurrent`, which takes a `GroovyObject`.
Once the receiver has been replaced, the writer now makes such a call with the
`invokeMethod` adapter, as for any other receiver. A `toString()` call inside
such a closure goes to the closure itself under static compilation until
GROOVY-12576 (#3102) is merged.
Tests: `ClosuresSTCTest.testClosureDelegateInInstanceInitializer` (also run
statically compiled by `ClosuresStaticCompileTest`), which fails without the
change. The `groovy`, `gls`, `bugs` and `org.codehaus.groovy` packages pass
(15,512 tests), apart from three `@Grab` tests
(`CoercionSTCTest.testCoerceToFunctionalInterface14`, also run by
`CoercionStaticCompileTests`, and
`GenericsSTCTest.testSelfReferentialTypeParameter5`) whose download failed
while other builds ran; they pass when rerun. The Checkstyle and CodeNarc gates
pass.
A regression in 5.0.0: 4.0.33 is correct, 5.0.8 and 6.0.0 are not.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]