Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
Description
Consider the following
class C { def m(@DelegatesTo(strategy=Closure.OWNER_ONLY, type='Void') Closure<?> block) { block.setResolveStrategy(Closure.OWNER_ONLY) block.setDelegate(null) return block.call() } def x() { 'C' } } trait T { def test() { new C().m { -> x() } // "x" must come from owner } def x() { 'T' } } class U implements T { } assert new U().test() == 'T'
Under static compilation, the implicit receiver metadata that is collected by StaticTypeCheckingVisitor is incorrect because the receiver T is only added for T$Trait$Helper under the delegate path. When using OWNER_ONLY, the trait is not checked and no direct method call target is set for "x()". So it falls back to dynamic behavior.
Attachments
Issue Links
- is a clone of
-
GROOVY-7242 calling trait method inside closure causes compiler error when CompileStatic is used
- Closed