Skip to content

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

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

Closed
nicolasstucki opened this issue May 17, 2017 · 0 comments
Closed

Comments

@nicolasstucki
Copy link
Contributor

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
   ...
}
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