Skip to content

Implicit conversion with given parameters not working #6914

Closed
@nicolasstucki

Description

@nicolasstucki

minimized code

trait Expr[T]
trait Liftable[T]

given autoToExpr[T] as Conversion[T, Expr[T]] given Liftable[T] {
  def apply(x: T): Expr[T] = ???
}

given as Liftable[Int] = ???
given as Liftable[String] = ???

def a: Expr[String] = "abc"

fails with

-- [E007] Type Mismatch Error: Foo.scala:12:22 ---------------------------------
12 |def a: Expr[String] = "abc"
   |                      ^^^^^
   |Found:    String("abc")
   |Required: Expr[String]
   |Note that implicit conversions cannot be applied because they are ambiguous;
   |both method Liftable_Int_given and method Liftable_String_given match type Liftable[Any]

expectation

The following implicit conversion should be inferred

def a: Expr[String] = autoToExpr[String].apply("abc")

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