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

Regression in valskalla/odin #18163

Closed
WojciechMazur opened this issue Jul 6, 2023 · 1 comment · Fixed by #18269
Closed

Regression in valskalla/odin #18163

WojciechMazur opened this issue Jul 6, 2023 · 1 comment · Fixed by #18269
Assignees
Labels
area:implicits related to implicits area:typer itype:bug regression This worked in a previous version but doesn't anymore
Milestone

Comments

@WojciechMazur
Copy link
Contributor

WojciechMazur commented Jul 6, 2023

Compiler version

Fails in 3.3.1-RC1
Works in 3.3.0
Bisect points to 12a8051

Minimized code

Needs further minimization, contramap function is provided using extension method (implemented as Scala2 implicit class LoggerSyntax)

//> using dep com.github.valskalla::odin-core:0.13.0
//> using dep org.typelevel::cats-effect:3.5.1

import cats.effect.{IO}
import cats.syntax.all._
import io.odin._
import io.odin.syntax.LoggerSyntax
import io.odin.loggers.WriterTLogger

@main def Test =
  val fails = new WriterTLogger[IO].contramap(identity) 
  val works = LoggerSyntax(new WriterTLogger[IO]).contramap(identity)

Output

[error] Found:    io.odin.loggers.WriterTLogger[cats.effect.IO]
[error] Required: ?{ contramap: ? }
[error] Note that implicit conversions cannot be applied because they are ambiguous;
[error] both method catsContravariantMonoidalForOrdering in object Invariant and method catsContravariantMonoidalForPartialOrdering in object Invariant match type cats.Contravariant[F]
[error]   val fails = new WriterTLogger[IO].contramap(identity)

Expectation

Should compile

@WojciechMazur WojciechMazur added itype:bug area:typer stat:needs minimization Needs a self contained minimization area:implicits related to implicits regression This worked in a previous version but doesn't anymore labels Jul 6, 2023
@WojciechMazur
Copy link
Contributor Author

Minimization:
Following code works in Scala 3.3.0 and fails in 3.3.1-RC
Worth things to notice:

  • We do have 2 contramap functions, one provided via LoggerSyntax other via Contravariant.Ops
  • ContravariantMonoidal given instances are not used, and they do not match our type. Code fails when we have at least 2 instances of them
  • Removal of import catsSyntax._ allow to compile code
  • Removal of import odinSyntax.LoggerSyntax and remaining catsSyntax would fail to compile the def fails
//> using options -Ykind-projector -language:implicitConversions

trait WriterT[F[_]: Contravariant, L, V]:
  def contramap[Z](fn: Z => V): WriterT[F, L, Z] = ???
trait Logger[F[_]]
class WriterTLogger[F[_]] extends Logger[WriterT[F, List[String], *]]

trait ContravariantMonoidal[F[_]] extends Invariant[F] with Contravariant[F]
trait Invariant[F[_]]
object Invariant {
  trait Foo[A]
  trait Bar[A]
  given ContravariantMonoidal[Foo] = ???
  given ContravariantMonoidal[Bar] = ???
}

trait Contravariant[F[_]] extends Invariant[F]
object Contravariant {
  trait Ops[F[_], A]:
    def contramap[B](f: B => A): F[B] = ???
}

object catsSyntax {
  implicit def toContravariantOps[F[_]: Contravariant, A](
      target: F[A]
  ): Contravariant.Ops[F, A] = ???
}

object odinSyntax {
  implicit class LoggerSyntax[F[_]](logger: Logger[F]):
    def contramap(f: String => String): Logger[F] = ???
}

import catsSyntax._
import odinSyntax.LoggerSyntax

def fails = new WriterTLogger[Option].contramap(identity)
def works = LoggerSyntax(new WriterTLogger[Option]).contramap(identity)

@WojciechMazur WojciechMazur removed the stat:needs minimization Needs a self contained minimization label Jul 20, 2023
@dwijnand dwijnand added this to the 3.3.1 milestone Jul 21, 2023
@dwijnand dwijnand linked a pull request Jul 22, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:implicits related to implicits area:typer itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants