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

Flakey implicit resolution with type alias Id[A] = A #10238

Closed
scabug opened this issue Mar 18, 2017 · 1 comment
Closed

Flakey implicit resolution with type alias Id[A] = A #10238

scabug opened this issue Mar 18, 2017 · 1 comment

Comments

@scabug
Copy link

scabug commented Mar 18, 2017

In the code below, implicit search for Monad[Id] succeeds by itself, but not always when it is part of a recursive search.

Most of the time it is impractical to define a type alias and annotate values with this type alias.

object Test {

  // Data types

  type Id[A] = A

  class MaybeT[F[_], A]

  type Maybe[A] = MaybeT[Id, A]

  type MaybeMaybe[A] = MaybeT[Maybe, A]


  // Typeclass

  trait Monad[F[_]]


  // Instances

  implicit val monadId: Monad[Id] = ???

  implicit def monadMaybeT[F[_]: Monad]: Monad[({ type λ[A] = MaybeT[F, A] })#λ] = ???

  implicit val monadOption: Monad[Option] = ???


  // Implicit search tests

  // OK
  implicitly[Monad[Id]]
  implicitly[Monad[({ type λ[A] = A })#λ]]

  // OK
  implicitly[Monad[Maybe]]

  // ERROR, despite asking for the same thing as before, but using a type lambda
  // error: could not find implicit value for parameter e: Test.Monad[[A]Test.MaybeT[[A]A,A]]
  implicitly[Monad[({ type λ[A] = MaybeT[Id, A] })#λ]]
  // implicitly[Monad[MaybeT[Id, ?]]]

  // OK
  implicitly[Monad[MaybeMaybe]]

  // ERROR, despite asking for the same thing as before, but using a type lambda
  // error: could not find implicit value for parameter e: Test.Monad[[A]Test.MaybeT[[A]Test.MaybeT[[A]A,A],A]]
  implicitly[Monad[({ type λ[A] = MaybeT[Maybe, A] })#λ]]
  // implicitly[Monad[MaybeT[Maybe, ?]]]

  // OK
  // Option instead of Maybe works,
  // because Option isn't a type alias containing Id.
  implicitly[Monad[({ type λ[A] = MaybeT[Option, A] })#λ]]
  // implicitly[Monad[MaybeT[Option, ?]]]
}
@scabug
Copy link
Author

scabug commented Mar 18, 2017

Imported From: https://issues.scala-lang.org/browse/SI-10238?orig=1
Reporter: Tomas Mikula (tomas.mikula-at-gmail.com)
Affected Versions: 2.12.1

TomasMikula added a commit to TomasMikula/scala that referenced this issue Sep 12, 2017
Can cause ambiguous implicits, so is under a compiler flag
-Yhk-typevar-unification.

Fixes scala/bug#10197
Fixes scala/bug#10213
Fixes scala/bug#10238
Fixes scala/bug#10372
Presents an alternative fix to scala/bug#6895.
TomasMikula added a commit to TomasMikula/scala that referenced this issue Sep 14, 2017
Can cause ambiguous implicits, so is under a compiler flag
-Yhk-typevar-unification.

Fixes scala/bug#10197
Fixes scala/bug#10213
Fixes scala/bug#10238
Fixes scala/bug#10372
Presents an alternative fix to scala/bug#6895.
TomasMikula added a commit to TomasMikula/scala that referenced this issue Sep 26, 2017
Can cause ambiguous implicits, so is under a compiler flag
-Yhk-typevar-unification.

Fixes scala/bug#10197
Fixes scala/bug#10213
Fixes scala/bug#10238
Fixes scala/bug#10372
Presents an alternative fix to scala/bug#6895.
TomasMikula added a commit to TomasMikula/scala that referenced this issue Sep 27, 2017
Can cause ambiguous implicits, so is under a compiler flag
-Yhk-typevar-unification.

Fixes scala/bug#10197
Fixes scala/bug#10213
Fixes scala/bug#10238
Fixes scala/bug#10372
Presents an alternative fix to scala/bug#6895.
TomasMikula added a commit to TomasMikula/scala that referenced this issue Sep 27, 2017
Can cause ambiguous implicits, so is under the compiler flag
-Xsource:2.13

Fixes scala/bug#10185
Fixes scala/bug#10195
Fixes scala/bug#10197
Fixes scala/bug#10213
Fixes scala/bug#10238
Fixes scala/bug#10372
Presents an alternative fix to scala/bug#6895.
TomasMikula added a commit to TomasMikula/scala that referenced this issue Sep 27, 2017
Can cause ambiguous implicits, so is under the compiler flag
-Xsource:2.13

Fixes scala/bug#10185
Fixes scala/bug#10195
Fixes scala/bug#10197
Fixes scala/bug#10213
Fixes scala/bug#10238
Fixes scala/bug#10372
Presents an alternative fix to scala/bug#6895.
TomasMikula added a commit to TomasMikula/scala that referenced this issue Sep 28, 2017
Can cause ambiguous implicits, so is under the compiler flag
-Xsource:2.13

Fixes scala/bug#10185
Fixes scala/bug#10195
Fixes scala/bug#10197
Fixes scala/bug#10213
Fixes scala/bug#10238
Fixes scala/bug#10372
Presents an alternative fix to scala/bug#6895.
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

1 participant