Skip to content

Polymorphic conversions not being utilized #13625

Open
@TimWSpence

Description

@TimWSpence

Compiler version

3.0.1

Minimized code

import scala.language.implicitConversions

trait FunctionK[F[_], G[_]] {
  def apply[A](fa: F[A]): G[A]
}

val x: FunctionK[Option, Option] = new FunctionK[Option, Option] {
  def apply[A](fa: Option[A]): Option[A] = fa
}

given [F[_], G[_]]: Conversion[FunctionK[F, G], [A] => F[A] => G[A]] with
  def apply(f: FunctionK[F, G]): [A] => F[A] => G[A] = [A] => (fa: F[A]) => f(fa)

val y: [A] => Option[A] => Option[A] = x

Output

-- [E007] Type Mismatch Error: test.scala:14:39 --------------------------------
14 |val y: [A] => Option[A] => Option[A] = x
   |                                       ^
   |           Found:    (x : FunctionK[Option, Option])
   |           Required: PolyFunction{apply: [A](x$1: Option[A]): Option[A]}

longer explanation available when compiling with `-explain`
1 error found

Expectation

My expectation is that this conversion should be applied? I tried a monomorphic variation:

import scala.language.implicitConversions

case class Foo()
case class Bar()

given Conversion[Foo, Bar] with
  def apply(f: Foo): Bar = Bar()

val foo: Foo = Foo()
val bar: Bar = foo

and that compiled successfully

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions