Skip to content

Case class unapply in partial function called on uninitialized module #2454

Closed
@nicolasstucki

Description

@nicolasstucki
class Bees {
  def f: PartialFunction[Bee, Unit] = {  case Bee(_) => ""  }

  f(new Bee("buzz"))

  case class Bee(value: String)
  // object Bee // With this it works
}

object Test {
  def main(args: Array[String]): Unit = {
    new Bees
  }
}

fails with

Caused by: java.lang.NullPointerException
	at Bees.Bees$f$$f$$anonfun$1$1(i2396.scala:6)
	at Bees$$anonfun$1.apply(i2396.scala:6)
	at Bees$$anonfun$1.apply(i2396.scala:6)
	at Bees.<init>(i2396.scala:9)
	at Test$.main(i2396.scala:17)
	at Test.main(i2396.scala)

where the bytecode has

public class Bees {
    public final Bees.Bee$ Bee$lzy1;

    public Bees() {
        this.f().apply(new Bees.Bee(this, "buzz"));
        this.Bee$lzy1 = new Bees.Bee$(this); // should be lazy
    }

    public final Bees.Bee$ Bee() { return this.Bee$lzy1; }  // should be initialized in here if needed
   ...
}

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