Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.8.4
-
Fix Version/s: 1.8.5, 2.0-beta-2
-
Component/s: None
-
Labels:None
-
Number of attachments :
Description
If you set the type of a shared closure variable to something else then this leads to a VerifierError such as:
Caused by: java.lang.VerifyError: (class: org/example/BookController, method: test signature: ()Ljava/lang/Object;) Incompatible argument to function at java.lang.Class.getDeclaredFields0(Native Method) at java.lang.Class.privateGetDeclaredFields(Class.java:2291) at java.lang.Class.getDeclaredFields(Class.java:1743)
This is because the Groovy is expecting a Reference but gets the new type that was set in an AST transform. Either a better error needs to be produced or you should not be allowed to set the type of a Reference to avoid painful debugging experience for users.
As a workaround, resolved by improving javadoc. It now explains when setType should be called and what should be done when an accessed variable exists.