Skip to content

Extension methods ambiguity when type argument is added #14451

Closed
@soronpo

Description

@soronpo

Just adding a type argument causes the compiler to report ambiguity where there is none.

Compiler version

v3.1.2-RC1

Minimized code

https://scastie.scala-lang.org/cI1XmUISRwmnIqc8rOThSw

class Foo

extension (dfVal: Foo)
  def prevOK(step: Int): Foo = ???
  def prevOK: Foo = ???
val ok = (new Foo).prevOK

extension (dfVal: Foo)
  def prevErr[S <: Int](step: S): Foo = ???
  def prevErr: Foo = ???
val err = (new Foo).prevErr

Output

value prevErr is not a member of Playground.Foo.
Extension methods were tried, but could not be fully constructed:

    Playground.prevErr(new Playground.Foo())

    prevErr(new Playground.Foo())    failed with

        Ambiguous overload. The overloaded alternatives of method prevErr in object Playground with types
         (dfVal: Playground.Foo): Playground.Foo
         (dfVal: Playground.Foo): [S <: Int](step: S): Playground.Foo
        both match arguments (Playground.Foo)

Expectation

No error.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions