Skip to content

Ambiguous overloads with type parameter and implicit conversion. #1381

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

Closed
nicolasstucki opened this issue Jul 11, 2016 · 2 comments · Fixed by #1389
Closed

Ambiguous overloads with type parameter and implicit conversion. #1381

nicolasstucki opened this issue Jul 11, 2016 · 2 comments · Fixed by #1389
Assignees

Comments

@nicolasstucki
Copy link
Contributor

dotty> object Foo {
         class Bar[T]
         implicit def const[T](x: T): Bar[T] = ???

         def bar[T](e: T): Any = ???
         def bar[T](e: Bar[T]): Any = ???

         val b: Bar[Int] = ???
         bar(b)
       } 
  ^
  bar(bar)
<console>:13: error: Ambiguous overload. The overloaded alternatives of method bar in object Foo$ with types
 [T](e: Foo.Bar[T])Any
 [T](e: T)Any
both match arguments (Foo.Bar[Int](Foo.bar))
scala> object Foo {
     |   class Bar[T]
     |   implicit def const[T](x: T): Bar[T] = ???
     | 
     |   def bar[T](e: T): Any = ???
     |   def bar[T](e: Bar[T]): Any = ???
     | 
     |   val b: Bar[Int] = ???
     |   bar(b)
     | }
defined object Foo
@nicolasstucki
Copy link
Contributor Author

It looks like in the original code they added the equivalent of def bar[T](e: T): Any = ??? as a bridge for the other overload. It looks like in their const was not being found implicitly in all their cases.

@odersky
Copy link
Contributor

odersky commented Jul 14, 2016

The problem is because dotty currently allows implicit conversions when deciding whether a method is applicable to the parameters of another, which is used as the test in isAsSpecific.
Let's try to drop this (should help make tests faster, too) and see what happens.

odersky added a commit to dotty-staging/dotty that referenced this issue Jul 14, 2016
Fix scala#1381: Overloading is now changed so that we first try without implicit searches.
Only if that leaves no applicable alternatives we try again with implicit search turned on.
This also fixes test case t2660, which got moved from neg to pos.
@odersky odersky self-assigned this Jul 14, 2016
odersky added a commit to dotty-staging/dotty that referenced this issue Jul 15, 2016
Fix scala#1381: Overloading is now changed so that we first try without implicit searches.
Only if that leaves no applicable alternatives we try again with implicit search turned on.
This also fixes test case t2660, which got moved from neg to pos.
odersky added a commit to dotty-staging/dotty that referenced this issue Jul 15, 2016
Adds the original test form scala#1381. t2660 looks similar.
Also adds some unrelated tests I had in the queue that now
compile.
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 18, 2016
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants