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

F[*] != F #9566

Open
djspiewak opened this issue Aug 14, 2020 · 3 comments
Open

F[*] != F #9566

djspiewak opened this issue Aug 14, 2020 · 3 comments
Assignees

Comments

@djspiewak
Copy link
Member

I don't have a nice minimization for this one yet, but it appears that type lambdas change the meaning of the type in subtle ways. Consider this commit: typelevel/cats-effect@ef891ca Note the use of G[*] in place of G throughout many of the functions in Resource, such as allocated. This is a workaround for a bug in Scala 2 (described here: typelevel/cats-effect#807). Unfortunately, it also seems to break Dotty entirely.

With the G[*] construction in place, Dotty refuses to compile this commit, with most of the errors taking the form of trying to find an Applicative for something like [A] ==>> IO[A]. Swapping out G[*] for G fixes the issue, though it sets us back in terms of Scala 2 support, since we need to find a different workaround for the aforementioned bug.

@smarter smarter added the stat:needs minimization Needs a self contained minimization label Aug 14, 2020
smarter added a commit to smarter/dotty that referenced this issue Dec 3, 2020
This is a tentative fix for scala#9566: if a type variable has a lower bound
more precise than Nothing, then further constraints can only restrict
its set of members, so there's no unknown members (...but the set of
members actually present is unknown, I think that's OK here but I should
rename that method and/or clarify the docs).
@odersky odersky closed this as completed Dec 27, 2020
@odersky
Copy link
Contributor

odersky commented Dec 27, 2020

Let's revisit this once we have a minimization.

@smarter
Copy link
Member

smarter commented Dec 27, 2020

I'd like to keep this open since I'm working on a fix for it, I have a sort-of-minimization for it:

import cats._
import cats.syntax.all.toFunctorOps

trait R[+M[_], +A] { def allocated[G[x] >: M[x]](implicit G: Functor[G]): G[G[Unit]] }

object Test {  
  def error[F[_], A](r: R[F, A])(implicit F: Functor[F]) = {
    r.allocated(using F).void // error with dotty, works with scala 2
  }
}

G[*] vs G doesn't make a difference here but I believe it's the same underlying issue.

@smarter smarter reopened this Dec 27, 2020
@smarter smarter self-assigned this Dec 27, 2020
@griggt
Copy link
Collaborator

griggt commented Dec 29, 2020

Here's a self-contained example (derived from the cats-effect codebase at the commit in the original post) where G[*] vs. G makes a difference:

trait Applicative[F[_]]

trait IO[+A]

object IO {
  def apply[A](thunk: => A): IO[A] = ???
  implicit def applicativeForIO: Applicative[IO] = ???
}

trait Resource[+F[_], +A] {
  def map[G[x] >: F[x], B](f: A => B)(implicit F: Applicative[G[*]]): Resource[G[*], B] = ???
}

object Resource {
  def liftF[F[_], A](fa: F[A])(implicit F: Applicative[F]): Resource[F, A] = ???
}

object Test {
  def test = for {
    _ <- Resource.liftF(IO {})
  } yield ()
}

Compiled with current dotty master:

$ dotc -Ykind-projector i9566.scala
-- Error: i9566.scala:21:12 ----------------------------------------------------
21 |  } yield ()
   |            ^
   |no implicit argument of type Applicative[G] was found for parameter F of method map in trait Resource

It compiles successfully after swapping G for G[*] .

It also compiles successfully with G[*] and Scala 2.13.4 (and kind projector plugin).


With regards to the original post, it seems like the majority of the errors are due to implicit search failures, and the remainder are fixed by #10205?

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

5 participants