Github user retronym commented on the issue:

    https://github.com/apache/spark/pull/19675
  
    I suppose the problematic case is:
    
    ```
    scala> :javap p2.C$D#$anonfun$test$1
      public static final java.lang.String $anonfun$test$1(p2.C$D, 
java.lang.String);
        descriptor: (Lp2/C$D;Ljava/lang/String;)Ljava/lang/String;
        flags: ACC_PUBLIC, ACC_STATIC, ACC_FINAL, ACC_SYNTHETIC
        Code:
          stack=2, locals=2, args_size=2
             0: new           #51                 // class 
java/lang/StringBuilder
             3: dup
             4: invokespecial #55                 // Method 
java/lang/StringBuilder."<init>":()V
             7: aload_0
             8: invokevirtual #57                 // Method 
p2$C$D$$$outer:()Lp2/C;
            11: invokevirtual #61                 // Method 
p2/C.c:()Ljava/lang/String;
            14: invokevirtual #65                 // Method 
java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
            17: aload_1
            18: invokevirtual #65                 // Method 
java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
            21: invokevirtual #68                 // Method 
java/lang/StringBuilder.toString:()Ljava/lang/String;
            24: areturn
          LocalVariableTable:
            Start  Length  Slot  Name   Signature
                0      25     0 $this   Lp2/C$D;
                0      25     1     x   Ljava/lang/String;
          LineNumberTable:
            line 1: 0
        MethodParameters:
          Name                           Flags
          $this                          final synthetic
          x                              final
    
    ```
    
    Where you'd prefer to eagerly capture `C.this.c`, rather than capturing `D`.
    
    You could do that manually as:
    
    ```
    scala> :paste -raw
    // Entering paste mode (ctrl-D to finish)
    
    package p3; class C { val c = "c"; class D { def test = { val capturedC = 
c; (x: String) => capturedC + x } } }
    ```
    
    In general, this could change semantics, `x` might not be initialized by 
`C.<init>` at the time of the lambda capture. Spores is a good solution here: 
you have do the rewrite manually (so the semantic change is your 
responsibility!), but spores will make sure you've remembered to do it.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to