simulacrum icon indicating copy to clipboard operation
simulacrum copied to clipboard

Compiler error when using type constraint

Open ssanj opened this issue 7 years ago • 0 comments

Hi,

If I try and use Simulcrum on the following:

@typeclass trait Functor[F[_]] { self =>
  def map[A, B](fa: F[A])(f: A => B): F[B]

  def widen[A, B >: A](fa: F[A]): F[B] = fa.asInstanceOf[F[B]]

  def xyz[A, B](ff: F[A => B])(a: A): F[B]
}

I get a compiler error:

<pastie>:18: error: not found: type A
  def widen[A, B >: A](fa: F[A]): F[B] = fa.asInstanceOf[F[B]]
                    ^
<pastie>:15: error: type arguments [C,B] do not conform to method widen's type parameter bounds [A,B >: A]
@typeclass trait Functor[F[_]] { self =>
 ^

If I rewrite widen not to use a type bound:

@typeclass trait Functor[F[_]] { self =>
  def map[A, B](fa: F[A])(f: A => B): F[B]

  def widen[A, B](fa: F[A])(implicit ev: A <:< B): F[B] = fa.asInstanceOf[F[B]]

  def xyz[A, B](ff: F[A => B])(a: A): F[B]
}

then I don't get any compilation errors.

Am I using Simulcrum incorrectly or is this a bug?

ssanj avatar Oct 31 '18 14:10 ssanj