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

Apply with default parameters on companion object causes compiler crash #11460

Open
franktominc opened this Issue Mar 30, 2019 · 1 comment

Comments

Projects
None yet
3 participants
@franktominc
Copy link

commented Mar 30, 2019

When you implement the apply in the companion object using default parameters and try to call it without providing any argument the compiler crash.

This compiles fine:

case class test private (foo: Map[String, List[Int]],
                         bar: List[Int],
                         baz: Map[String, List[String]]) {}

case object test {
  def getInstance = apply(Map.empty, List.empty, Map.empty)

  def apply(foo: Map[String, List[Int]],
            bar: List[Int],
            baz: Map[String, List[String]]) = new test(foo, bar, baz)
}

This compiles too:

case class test private (foo: Map[String, List[Int]],
                         bar: List[Int],
                         baz: Map[String, List[String]]) {}

case object test {
  def getInstance = apply(Map.empty)

  def apply(foo: Map[String, List[Int]] = Map.empty,
            bar: List[Int] = List.empty,
            baz: Map[String, List[String]] = Map.empty) =
    new test(foo, bar, baz)
}

This doesn't:

case class test private (foo: Map[String, List[Int]],
                           bar: List[Int],
                           baz: Map[String, List[String]]) {}

case object test {
  def getInstance = apply()

  def apply(foo: Map[String, List[Int]] = Map.empty,
            bar: List[Int] = List.empty,
            baz: Map[String, List[String]] = Map.empty) =
    new test(foo, bar, baz)
}

compiler output: https://gist.github.com/franktominc/c10fe33bf31fadf341a306b4e7bdfc1d

tested on 2.12.8, 2.12.7 and 2.12.5

@som-snytt

This comment has been minimized.

Copy link

commented Apr 2, 2019

Removing the weird case from the object doesn't fix it. Removing case from the class does.

I wonder if disallowing the circular dependency in the object is reasonable. Maybe if the defaults are expressed statically if possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.