Skip to content

Typeclass extension methods do not see instances put in typeclass companion object #21503

Open
@goshacodes

Description

@goshacodes

Hello, not sure if this is a bug.
Extension method =:= do not see typeclass instances put in typeclass companion object, it feels not very clear why should I use import in this case and how this import fixes search of extension method
If I put instance in concrete type companion object syntax works without import

Compiler version

3.3.3
3.5.0

Minimized code

trait Eq[A]:
  def eqv(first: A, second: A): Boolean

  extension (first: A)
    def =:=(second: A): Boolean = eqv(first, second)

object Eq:
  given Eq[String] = (_, _) => true

case class User(str: String) 

object User:
  given Eq[User] = (_, _) => true

User("") =:= User("") // compiles
"" =:= "" // not compiles without import Eq.given

Output

value =:= is not a member of String, but could be made available as an extension method.

The following import might fix the problem:

  import Playground.Eq.given_Eq_String

Expectation

Compiles without import Eq.given

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