Skip to content

implicit search for extension methods seems to give up too early #5781

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
drdozer opened this issue Jan 22, 2019 · 3 comments
Closed

implicit search for extension methods seems to give up too early #5781

drdozer opened this issue Jan 22, 2019 · 3 comments

Comments

@drdozer
Copy link

drdozer commented Jan 22, 2019

When searching for extension methods, I'm finding categories of things that don't work which involve implicit defs to summon the instances.

trait Semigroup[T] {
  def (lhs: T) append (rhs: T): T
}

object Semigroup {
  implicit object stringAppend extends Semigroup[String] {
    override def (lhs: String) append (rhs: String): String = lhs + rhs
  }

  implicit def sumSemigroup[N](implicit N: Numeric[N]): Semigroup[N] = new {
    override def (lhs: N) append (rhs: N): N = N.plus(lhs, rhs)
  }
}


object Main {
  def main(args: Array[String]): Unit = {
    import Semigroup.stringAppend // necessary to make the extension method visible
    println("Hi" append " mum")

    import Semigroup.sumSemigroup // this is not sufficient
    println(1 append 2) // this won't compile

    implicit val intSumAppend: Semigroup[Int] = sumSemigroup[Int]
    println(3 append 4) // this will
  }
}
@LPTK
Copy link
Contributor

LPTK commented Jan 23, 2019

Seems like a duplicate of #5773, which I opened yesterday 😄

@drdozer
Copy link
Author

drdozer commented Jan 23, 2019

Could well be.

@Blaisorblade
Copy link
Contributor

Closing for now as duplicate; feel free to add the example to the other issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants