Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-9333

`this` within native lambda does not reference the instance of enclosing class

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.0.0-rc-2
    • Fix Version/s: 3.0.0-rc-3
    • Component/s: None
    • Labels:
      None

      Description

      import groovy.transform.CompileStatic
      
      @CompileStatic
      public class Test4 {
          public static void main(String[] args) {
              new Test4().p();
          }
          
          public String hello = "Hello ";
      
          public void p() {
              assert ['Hello Jochen', 'Hello Daniel'] == ["Jochen", "Daniel"].stream().map(e -> this.hello + e).toList();
          }
      }
      

      Error message:

      java.lang.ClassCastException: class Test4$_p_lambda1 cannot be cast to class Test4 (Test4$_p_lambda1 and Test4 are in unnamed module of loader groovy.lang.GroovyClassLoader$InnerLoader @1e05551b)
      
      	at Test4$_p_lambda1.doCall(ConsoleScript2:12)
      
      	at Test4.p(ConsoleScript2:12)
      
      	at Test4.main(ConsoleScript2:6)
      
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      
      	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      
      	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                emilles Eric Milles
                Reporter:
                daniel_sun Daniel Sun
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m