Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ambiguity between extension methods and methods reached through conversions #19715

Closed
odersky opened this issue Feb 17, 2024 · 1 comment · Fixed by #19717
Closed

Ambiguity between extension methods and methods reached through conversions #19715

odersky opened this issue Feb 17, 2024 · 1 comment · Fixed by #19717
Assignees
Labels
area:implicits related to implicits itype:bug
Milestone

Comments

@odersky
Copy link
Contributor

odersky commented Feb 17, 2024

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.

@odersky odersky added the stat:needs triage Every issue needs to have an "area" and "itype" label label Feb 17, 2024
@odersky odersky self-assigned this Feb 17, 2024
@odersky odersky added itype:bug area:implicits related to implicits and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 17, 2024
@odersky
Copy link
Contributor Author

odersky commented Feb 17, 2024

Note that we already prefer extensions over conversions in the case where an implicit reference is overloaded.

odersky added a commit to dotty-staging/dotty that referenced this issue Feb 17, 2024
@Kordyjan Kordyjan added this to the 3.4.2 milestone Mar 28, 2024
@Kordyjan Kordyjan modified the milestones: 3.4.2, 3.5.0 May 10, 2024
WojciechMazur pushed a commit that referenced this issue Jul 1, 2024
WojciechMazur pushed a commit that referenced this issue Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:implicits related to implicits itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants