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 was found for implicit parameter #14171

Open
fdietze opened this issue Dec 24, 2021 · 3 comments · May be fixed by #14586
Open

no implicit argument was found for implicit parameter #14171

fdietze opened this issue Dec 24, 2021 · 3 comments · May be fixed by #14586

Comments

@fdietze
Copy link

fdietze commented Dec 24, 2021

Compiler version

3.1.1-RC1

Minimized code

trait MyTypeclass[F[_]]
def f[F[_]: MyTypeclass, U](t:F[U]) = ???

type MyType[T] = String
implicit val impl:MyTypeclass[MyType] = ???

val stream:Option[MyType[Int]] = ???
for {
  keyStream <- stream
  x = 17 // uncommenting this line makes it compile
} yield f(keyStream)

https://scastie.scala-lang.org/t7ixyW5qQtqxSnQWGIsQDw

Output

no implicit argument of type Playground.MyTypeclass[Comparable] was found
for an implicit parameter of method f in object Playground

Expectation

Should compile like in Scala 2.13

@joroKr21
Copy link
Member

So odd - where did String come from? 🤔

[[syntax trees at end of                     typer]] // rs$line$1
package repl {
  final lazy module val rs$line$1: repl.rs$line$1 = new repl.rs$line$1()
  final module class rs$line$1() extends Object() { this: repl.rs$line$1.type =>
    trait MyTypeclass[F[_ >: Nothing <: Any] >: Nothing <: Any]() extends Object
       {
      F[_$1]
    }
    def f[F[_ >: Nothing <: Any] >: Nothing <: Any, U >: Nothing <: Any](t: F[U]
      )
    (implicit evidence$1: MyTypeclass[F]): Nothing = ???
    type MyType[T >: Nothing <: Any] = String
    implicit val impl: MyTypeclass[MyType] = ???
    val stream: Option[MyType[Int]] = ???
    val res0: Option[Nothing] =
      stream.map[(MyType[Int], Int)](
        {
          def $anonfun(keyStream: MyType[Int]): (MyType[Int], Int) =
            {
              val x: Int = 17
              Tuple2.apply[MyType[Int], Int](keyStream, x)
            }
          closure($anonfun)
        }
      ).map[Nothing](
        {
          def $anonfun(x$1: (MyType[Int], Int)): Nothing =
            x$1:(x$1 : (MyType[Int], Int)) @unchecked match
              {
                case Tuple2.unapply[String, Int](keyStream @ _, x @ _) =>
                  f[Comparable, String](keyStream)(
                    /* missing */summon[MyTypeclass[Comparable]]
                  )
              }
          closure($anonfun)
        }
      )
  }
}

@smarter
Copy link
Member

smarter commented Jan 3, 2022

In general, we don't guarantee that type aliases are preserved by type inference (and neither does scala 2, although it happens to work in this case), so this might be a won't fix.

@joroKr21
Copy link
Member

joroKr21 commented Jan 3, 2022

I could make this example work but I couldn't make type MyType[T] = x.type work when there is a singleton type underneath. I think we should put in some effort retain more aliases but it would be a painstaking case-by-case process.

@dwijnand dwijnand linked a pull request Jan 10, 2022 that will close this issue
@pweisenburger pweisenburger linked a pull request Feb 28, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants