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

Order of classes and companion object matters in implicit resolution #6515

Closed
scabug opened this issue Oct 11, 2012 · 5 comments
Closed

Order of classes and companion object matters in implicit resolution #6515

scabug opened this issue Oct 11, 2012 · 5 comments

Comments

@scabug
Copy link

scabug commented Oct 11, 2012

It seems that, when dealing with implicit resolution, the order of definition of classes and companion object matters. The minimal example I was able to cook up is:

trait Counter[A] {
  def count(a: A): Int
}

object Foo {
  def foo[A](a: A)(implicit c: Counter[A]) = c.count(a)
}

case class Bar(id: Int) {
  import Foo._

  def count = foo(this)
}

object Bar {
  implicit object BarCounter extends Counter[Bar] {
    def count(b: Bar) = b.id
  }
}

This fails to compile saying "could not find implicit value for parameter c: Counter[Bar]"

On the other hand, if we define object Bar before case class Bar, it compiles fine.

I should also mention that this problem only arises with implicit resolution. If we explicitly pass the BarCounter object, everything compiles fine.

@scabug
Copy link
Author

scabug commented Oct 11, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6515?orig=1
Reporter: Andrea Ferretti (andrea)
Affected Versions: 2.9.1
Duplicates #3466
Attachments:

  • Bar.scala (created on Oct 11, 2012 7:22:15 AM UTC, 286 bytes)

@scabug
Copy link
Author

scabug commented Oct 15, 2012

@adriaanm said (edited on Oct 15, 2012 2:26:08 PM UTC):
I'm not sure this is going to be easy to fix or even whether it should. Assigning to meeting for input.

@scabug
Copy link
Author

scabug commented Oct 15, 2012

@adriaanm said:
(Note that it also doesn't work when Bar is not a case class.)

@scabug
Copy link
Author

scabug commented Jul 10, 2013

@adriaanm said:
Unassigning and rescheduling to M6 as previous deadline was missed.

@scabug
Copy link
Author

scabug commented Jul 26, 2013

@paulp said:
Duplicate of #3466.

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

2 participants