Skip to content

Typecheck error on HKT inside AnyVal with uncheckedVariance #12028

@Odomontois

Description

@Odomontois

reproduction steps

using Scala 2.13\ 2.12 with the following code

import scala.annotation.unchecked.uncheckedVariance

trait TypeClass[F[_]] {
  def action[A](foo: F[A], bar: F[A]): F[A]
}

class Syntax[F[+_], A](private val foo: F[A]) extends AnyVal {
  def action[F1[+x] >: F[x] @uncheckedVariance](
      bar: F1[A]
  )(implicit tc: TypeClass[F1]): F1[A] =
    tc.action[A](foo, bar)
}

problem

compilation produces error

[error] scala.reflect.internal.Types$TypeError: type mismatch;
[error]  found   : F1(in method action$extension)[A1(in method action$extension),B1(in method action$extension)]
[error]  required: (some other)A1(in method action$extension) (some other)F1(in method action$extension) (some other)B1(in method action$extension)

Any of the following actions:

  • remove @uncheckedVariance
  • remove extends AnyVal

make the error disappear

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions