[
https://issues.apache.org/jira/browse/GROOVY-12654?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Scott Murphy Heiberg updated GROOVY-12654:
------------------------------------------
Affects Version/s: 5.1.3
(was: 7.0.0-alpha-1)
> SC: calling an instance method of Class without a receiver in a static method
> fails verification or uses the wrong receiver
> ---------------------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12654
> URL: https://issues.apache.org/jira/browse/GROOVY-12654
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 5.0.8, 5.1.3, 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> {code:groovy}
> @groovy.transform.CompileStatic
> class C {
> static Object sm() { getName() }
> static Object st() { toString() }
> static Object sp(Class type) { getName() }
> }
> println C.sm(); println C.st(); println C.sp(String)
> {code}
> *Actual:* {{java.lang.VerifyError: Bad local variable type}}
> ({{C.sm()Ljava/lang/Object; @0: aload_0}}). With only {{sp}}, it prints
> {{java.lang.String}}: the method is called on the parameter. A static field
> initializer such as {{static String p = getName()}} fails the same way in the
> static initializer. With closure packing ({{groovy.target.closure.pack=true}}
> or {{@PackedClosures}}), a closure in a static method is hoisted into a
> static method, so {{static m() ... toString() inside a closure}} fails
> verification the same way.
> *Expected:* {{C}}, {{class C}}, {{C}}, as in dynamic and {{@TypeChecked}}
> code, and as in 4.0.33.
> Cause: for an implicit-this call to a method declared outside the enclosing
> class, {{StaticInvocationWriter.writeDirectMethodCall}} builds the receiver
> {{Type.this}}, which in a static method loads local slot 0 instead of the
> class.
> Verified: 4.0.33 prints the expected values; 5.0.8, 6.0.0 and master fail.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)