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

Invalid implicit resolution attempt for higher kind #10849

Closed
carymrobbins opened this Issue Apr 25, 2018 · 6 comments

Comments

Projects
None yet
3 participants
@carymrobbins

carymrobbins commented Apr 25, 2018

Notice that scalac attempts to resolve an implicit for MonoidK[Option[String]] whereas it should be trying to resolve MonoidK[Option] -

Welcome to Scala 2.12.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_131).
Type in expressions for evaluation. Or try :help.

scala> import shapeless._, cats._, cats.implicits._

scala>   object polyEmpty extends Poly0 {
     |     implicit def cases[F[_], V](implicit F: MonoidK[F]): ProductCase.Aux[HNil, F[V]] =
     |       at[F[V]](F.empty)
     |   }
defined object polyEmpty

scala> HList.fillWith[Option[String] :: HNil](polyEmpty)
<console>:22: this.polyEmpty.cases is not a valid implicit value for shapeless.poly.Case0.Aux[polyEmpty.type,Option[String]] because:
hasMatchingSymbol reported error: could not find implicit value for parameter F: cats.MonoidK[Option[String]]
       HList.fillWith[Option[String] :: HNil](polyEmpty)
                                             ^
<console>:22: hlist.this.FillWith.hconsFill is not a valid implicit value for shapeless.ops.hlist.FillWith[polyEmpty.type,Option[String] :: shapeless.HNil] because:
hasMatchingSymbol reported error: could not find implicit value for parameter hc: shapeless.poly.Case0.Aux[polyEmpty.type,Option[String]]
       HList.fillWith[Option[String] :: HNil](polyEmpty)
                                             ^
<console>:22: error: could not find implicit value for parameter fillWith: shapeless.ops.hlist.FillWith[polyEmpty.type,Option[String] :: shapeless.HNil]
       HList.fillWith[Option[String] :: HNil](polyEmpty)
                                             ^
@carymrobbins

This comment has been minimized.

carymrobbins commented Apr 25, 2018

One workaround I came up with was to proxy the higher-kinded type class -

scala> :paste
// Entering paste mode (ctrl-D to finish)

  trait Field[A] {
    def combine(x: A, y: A): A
    def empty: A
  }

  object Field {
    implicit def fromMonoidK[F[_], A](implicit F: MonoidK[F]): Field[F[A]] = new Field[F[A]] {
      override def combine(x: F[A], y: F[A]): F[A] = F.combineK(x, y)
      override def empty: F[A]                     = F.empty
    }
  }

// Exiting paste mode, now interpreting.

defined trait Field
defined object Field

scala>   object polyEmpty extends Poly0 {
     |     implicit def cases[A](implicit F: Field[A]): Case0[A] = at[A](F.empty)
     |   }

scala> import shapeless.ops.hlist.FillWith

scala> val fill = implicitly[FillWith[polyEmpty.type, Option[String] :: HNil]]

scala> fill.apply
res1: fill.Out = None :: HNil
@joroKr21

This comment has been minimized.

joroKr21 commented Apr 27, 2018

AppliedTypeVar should probably override some methods.

@joroKr21

This comment has been minimized.

joroKr21 commented Apr 28, 2018

need minimization without shapeless for testing

joroKr21 added a commit to joroKr21/scala that referenced this issue Apr 28, 2018

joroKr21 added a commit to joroKr21/scala that referenced this issue Apr 28, 2018

@carymrobbins

This comment has been minimized.

carymrobbins commented Apr 28, 2018

@joroKr21 Not sure if this helps, but I wrote a very minimal Generic type class that should be (nearly) a drop-in replacement. In this case we'd have to get rid of ZipWith and FillWith too, but I assume we can just have simpler, noop definition.

MiniGeneric.scala

@joroKr21

This comment has been minimized.

joroKr21 commented Apr 28, 2018

Thanks! I forgot to mention it here, but I already added a test over at scala/scala#6573. All we need to trigger the bug is an Aux implicit (i.e. type parameters end up in a refinement) depending on a higher-kinded implicit.

@SethTisue

This comment has been minimized.

Member

SethTisue commented Apr 30, 2018

@joroKr21 I want to assign you the ticket as a record of who fixed it, but you'll need to accept my invite to the contributors team first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment