groovy
  1. groovy
  2. GROOVY-5146

Disallow setting of type on VariableExpression if isClosureSharedVariable() returns true from AST transforms

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major 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 :
      0

      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.

        Activity

        CÚdric Champeau made changes -
        Field Original Value New Value
        Assignee Cedric Champeau [ melix ]
        Hide
        CÚdric Champeau added a comment -

        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.

        Show
        CÚdric Champeau added a comment - 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.
        CÚdric Champeau made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.0-beta-2 [ 18072 ]
        Fix Version/s 1.8.5 [ 18071 ]
        Resolution Fixed [ 1 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            CÚdric Champeau
            Reporter:
            Graeme Rocher
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: