Skip to content

Calling case class constructor without apply fails #4466

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
Arthurm1 opened this issue May 5, 2018 · 1 comment
Closed

Calling case class constructor without apply fails #4466

Arthurm1 opened this issue May 5, 2018 · 1 comment

Comments

@Arthurm1
Copy link

Arthurm1 commented May 5, 2018

object Foo {
  case class Bar(map: Map[String, String]) 

  object Bar {
    def apply(str: String): Bar = ???
  }

  Bar(Map("A" -> "B"))
}

gives

-- [E050] Reference Error: /tmp/scastie7649626593689591865/src/main/scala/main.scala:8:2 
8 |  Bar(Map("A" -> "B"))
  |  ^^^
  |  object Bar in object Foo does not take parameters

works if using apply

  Bar.apply(Map("A" -> "B"))

works without companion object

object Foo {
  case class Bar(map: Map[String, String]) 

  Bar(Map("A" -> "B"))
}
@allanrenucci
Copy link
Contributor

This works:

def foo(m: Map[String, String]) = Bar(m)

@odersky odersky closed this as completed in 319d478 Aug 7, 2018
odersky added a commit that referenced this issue Aug 7, 2018
Fix #4466: Update contexts of FunProto when something else is tried
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

4 participants