Skip to content

implicit object is not available for implicit resolution #12440

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
myazinn opened this issue Aug 5, 2021 · 2 comments
Closed

implicit object is not available for implicit resolution #12440

myazinn opened this issue Aug 5, 2021 · 2 comments

Comments

@myazinn
Copy link

myazinn commented Aug 5, 2021

reproduction steps

using Scala 2.13.6,

trait Companion[T]

abstract class Service[T: Companion]

object Foo {
  // can't find required implicit
  class Impl extends Service[String]

  implicit object Impl extends Companion[String]
}

problem

I'm expecting the above code to compile but it doesn't. If I (1) add dummy line that calls for this implicit value too, or (2) change the definition order, or (3) change implicit object to implicit lazy val then the code compiles fine
1.

trait Companion[T]

abstract class Service[T: Companion]

object Foo {
  def unused: Any = implicitly[Impl.type]
  
  class Impl extends Service[String]

  implicit object Impl extends Companion[String]
}
trait Companion[T]

abstract class Service[T: Companion]

object Foo {
  implicit object Impl extends Companion[String]
  
  class Impl extends Service[String]
}
trait Companion[T]

abstract class Service[T: Companion]

object Foo {  
  class Impl extends Service[String]

  implicit lazy val Impl: Companion[String] = ???
}

I'm really surprized that (1) fixes this issue. Intuitively it should not affect implicit resolution of existing code at all.

Initially I've faced this issue on Scala 2.12.14 which has exactly the same behavior in this case. Also, if I compile this code in Scala 3 then it works fine. Maybe you will find it useful.

@myazinn myazinn changed the title implicit object is not available for implicit resolution if it's defined in another object implicit object is not available for implicit resolution Aug 5, 2021
@som-snytt
Copy link

#11751
helpfully links to
#8697

Note that in 3, explicit type was added.

@myazinn
Copy link
Author

myazinn commented Aug 5, 2021

@som-snytt
Got it, thanks.
Sorry for creating duplicate ticket, I couldn't find these tickets myself

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

2 participants