Skip to content

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

@Godin

Description

@Godin

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions