Skip to content

Ambiguity between extension methods and methods reached through conversions #19715

Closed
@odersky

Description

@odersky

Compiler version

3.4.1

Minimized example

class Tup():
  def app(n: Int): String = "a"

class NT(t: Tup):
  def toTup = t
object NT:
  extension (x: NT)
    def app(n: Int): Boolean = true
  given Conversion[NT, Tup] = _.toTup

def test =
  val nt = new NT(Tup())
  val x = nt.app(3)
  val _: Boolean = x

Output

16 |  val x = nt.app(3)
   |          ^^
   |Found:    (nt : NT)
   |Required: ?{ app: ? }
   |Note that implicit extension methods cannot be applied because they are ambiguous;
   |both given instance given_Conversion_NT_Tup in object NT and object NT provide an extension method `app` on (nt : NT)
   |
   | longer explanation available when compiling with `-explain`
1 error found

Expectation

This should compile, and the method in object NT should be chosen. An extension method available directly should be preferable over a member reachable through implicit conversions. But right now it reports an ambiguity.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions