Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anonymous functions in Scala 3 should not be filtered out #1432

Open
Godin opened this issue May 9, 2023 · 0 comments
Open

Anonymous functions in Scala 3 should not be filtered out #1432

Godin opened this issue May 9, 2023 · 0 comments

Comments

@Godin
Copy link
Member

Godin commented May 9, 2023

For the following Example.scala

object Example {
    def exec(task: Runnable) = {
        task.run();
    }

    def main(args: Array[String]) = {
        exec(() => {
            println("Hello")
        })
    }
}

execution of

scala-2.13.3/bin/scalac Example.scala
javap -v -p Example\$.class

produces

  public static final void $anonfun$main$1();
    descriptor: ()V
    flags: (0x1019) ACC_PUBLIC, ACC_STATIC, ACC_FINAL, ACC_SYNTHETIC
    Code:
      stack=2, locals=0, args_size=0
         0: getstatic     #56                 // Field scala/Predef$.MODULE$:Lscala/Predef$;
         3: ldc           #58                 // String Hello
         5: invokevirtual #62                 // Method scala/Predef$.println:(Ljava/lang/Object;)V
         8: return
      LineNumberTable:
        line 8: 0

whereas execution of

scala3-3.2.2/bin/scalac -d classes3 Example.scala
javap -v -p Example\$.class

produces

  private final void main$$anonfun$1();
    descriptor: ()V
    flags: (0x1012) ACC_PRIVATE, ACC_FINAL, ACC_SYNTHETIC
    Code:
      stack=2, locals=1, args_size=1
         0: getstatic     #60                 // Field scala/Predef$.MODULE$:Lscala/Predef$;
         3: ldc           #62                 // String Hello
         5: invokevirtual #66                 // Method scala/Predef$.println:(Ljava/lang/Object;)V
         8: return
      LineNumberTable:
        line 7: 0
        line 8: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       9     0  this   LExample$;

The first one is recognized by #912

if (isScalaClass(context)) {
if (methodNode.name.startsWith("$anonfun$")) {
return;
}
}

and won't be filtered out, whereas the second one will be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant