Skip to content

Type inference bug in Scala 3.1.2 #15160

Closed
@alexandru

Description

@alexandru

I'm unsure if I'm reporting this issue in the right place.

Compiler version

3.1.2 — the issue does not happen in 3.0.x or in 3.1.1.

First bad commit db5956b in #13886

Minimized code

Noticed it while upgrading to 3.1.2 in monix/newtypes:

trait Eq[A] {
  def eqv(a1: A, a2: A): Boolean
}

given stringEq: Eq[String] with {
  def eqv(a1: String, a2: String) = a1 == a2
}

abstract class Newtype[Src] {
  opaque type Type = Src

  protected final def derive[F[_]](using ev: F[Src]): F[Type] = ev
}

object Sample extends Newtype[String] {
  given eq: Eq[Type] = derive
}

Output

[error] -- Error: .../Sample.scala:16:29
[error] 16 |  given eq: Eq[Type] = derive
[error]    |                             ^
[error]    |no implicit argument of type F[String] was found for parameter ev of method derive in class Newtype
[error]    |
[error]    |where:    F is a type variable with constraint <: Eq
[error] one error found

Expectation

The code should compile just fine, as it does with 3.1.1, 3.0.2, or 2.13.x.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions