Skip to content

Compiler error when using type constraint #115

@ssanj

Description

@ssanj

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions