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

No implicit argument of type F[T] was found (works in Scala 2) #15210

Open
fdietze opened this issue May 18, 2022 · 4 comments
Open

No implicit argument of type F[T] was found (works in Scala 2) #15210

fdietze opened this issue May 18, 2022 · 4 comments

Comments

@fdietze
Copy link

fdietze commented May 18, 2022

Compiler version

3.1.3-RC2

Minimized code

trait Observer[-T]
trait PublishSubject[A] extends Observer[A]

trait Source[H[_]] 
implicit object source extends Source[PublishSubject]


final def foo[F[_]: Source, T2 <: String](source: F[T2]) = ???
final def foo[F[_]: Source, T2 <: Option[String]](source: F[T2], dummy: Unit = ())  = ???


val x:PublishSubject[Option[String]] = ???
foo(x)

https://scastie.scala-lang.org/7HyQgDhzSgmRUO0mJPgPwA

Output

no implicit argument of type Playground.Source[Playground.Observer] was found for an implicit parameter of method foo in object Playground

Expectation

Should compile like in Scala 2.13

@fdietze fdietze added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels May 18, 2022
@bishabosha
Copy link
Member

it compiles if you make PublishSubject contravariant:

trait Observer[-T]
trait PublishSubject[-A] extends Observer[A]

trait Source[H[_]] 
implicit object source extends Source[PublishSubject]


def foo[F[_]: Source, T2 <: String](source: F[T2]) = ()
def foo[F[_]: Source, T2 <: Option[String]](source: F[T2], dummy: Unit = ())  = ()


val x:PublishSubject[Option[String]] = new PublishSubject[Option[String]] {}
foo(x)

@fdietze
Copy link
Author

fdietze commented May 18, 2022

it compiles if you make PublishSubject contravariant:

Yes, I noticed that too. It was quite difficult to find this reproducing piece of code.

@nicolasstucki nicolasstucki added area:typer and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels May 19, 2022
@nicolasstucki
Copy link
Contributor

It also fails with foo(x)(source) but not with foo(x, ())(source). There might be an issue with overload resolution related to implicit search.

@smarter
Copy link
Member

smarter commented Apr 14, 2023

Minimized from https://contributors.scala-lang.org/t/better-type-inference-for-scala-send-us-your-problematic-cases/2410/173, here's another case where overloading and implicit search seem to break in Scala 3 compared to Scala 2:

class BodyReadable[R]

trait CustomResponse {
  def body: String
  def body[T: BodyReadable]: T
}

class MustExpectable[T] {
  def must: Any = ???
}
trait MustExpectations {
  import scala.language.implicitConversions
  implicit def theValue[T](t: T): MustExpectable[T] = ???
}

object Test extends MustExpectations {

  val r: CustomResponse = ???
  r.body.must // error

  val rbody = r.body
  rbody.must // OK
}

This affects play where it is worked around using a lot of imports: playframework/playframework@8d48699

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