Skip to content

Ambiguous overload on functions differing by implicits #13768

Closed
@Adam-Vandervorst

Description

@Adam-Vandervorst

Compiler version

3.0.2

Minimized code

class Base
class A extends Base
class B extends Base

trait T[X]

given T[A]()


def f[X <: Base](ins: X)(using T[X]) = "with T"
def f[X <: Base](ins: X) = "without T"

@main def m = f(A())

Output

Ambiguous overload. The overloaded alternatives of method f with types
 [X <: Base](ins: X)(using x$2: T[X]): String
 [X <: Base](ins: X): String
both match arguments (A)
  f(A())

Expectation

To work similar to the regular case:

def f[X <: Base](ins: X)(t: T[X]) = "with T"
def f[X <: Base](ins: X) = "without T"

I first suspected this to be an issue with the implicit being optional in that case, but the following doesn't work either:

def f[X <: Base](ins: X)(using T[X]) = "with T"
def f[X <: Base](ins: X)(using NotGiven[T[X]]) = "without T"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions