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

Extension method fails to construct with <overloaded XX> does not take parameters #13668

Closed
soronpo opened this issue Oct 3, 2021 · 2 comments · Fixed by #15636
Closed

Extension method fails to construct with <overloaded XX> does not take parameters #13668

soronpo opened this issue Oct 3, 2021 · 2 comments · Fixed by #15636
Assignees
Labels
Milestone

Comments

@soronpo
Copy link
Contributor

soronpo commented Oct 3, 2021

When an extension method is defined for a typeclass more than once but with different arguments, it fails to construct if the method argument has type arguments. If we were to remove the type arguments, the method construction works.

Compiler version

v3.1.0-RC2

Minimized code

class MyType()
trait Candidate[R]
given Candidate[MyType] with {}
class Fuzzy[W]()
class Fuzzy1()
class Bear()

extension [L](lhs: L)(using Candidate[L])
  def +[RW](rhs: Fuzzy[RW]): Unit = {}
  def +(rhs: Bear): Unit = {}
  def -(rhs: Fuzzy1): Unit = {}
  def -(rhs: Bear): Unit = {}

val works = MyType() - Fuzzy1()
val fails = MyType() + Fuzzy[1]()

Output

[error] 15 |val fails = MyType() + Fuzzy[1]()
[error]    |            ^^^^^^^^^^
[error]    |      value + is not a member of MyType.
[error]    |      An extension method was tried, but could not be fully constructed:
[error]    |
[error]    |          +()    failed with
[error]    |
[error]    |              value +: <overloaded +> does not take parameters
[error] one error found

Expectation

No error.

@soronpo
Copy link
Contributor Author

soronpo commented Oct 4, 2021

Workaround: move the using clause to the method parts:

extension [L](lhs: L) 
  def +[RW](rhs: Fuzzy[RW])(using Candidate[L]): Unit = {}
  def +(rhs: Bear)(using Candidate[L]): Unit = {}
  def -(rhs: Fuzzy1)(using Candidate[L]): Unit = {}
  def -(rhs: Bear)(using Candidate[L]): Unit = {}

@ValeriePe
Copy link

This issue was picked for the Issue Spree 18 of July 5th which takes place in a week from now. @griggt @gagandeepkalra will be working on it. If you have any insight into the issue or guidance on how to fix it, please leave it here.

@griggt griggt self-assigned this Jul 8, 2022
griggt added a commit to griggt/dotty that referenced this issue Jul 9, 2022
In some cases while going deeper into alternatives during overload resolution,
we may end up with a nested polytype after dropping contextual parameters.

In particular this can happen for an extension with a `using` clause, as seen
in tests/pos/i11713.scala and tests/pos/i13668.scala.

The overload applicability test fails here unless the type parameter lists
are merged.

Co-authored-by: Gagandeep Kalra <gagandeepkalra1994@gmail.com>
Co-authored-by: Mark T. Kennedy <mtk@acm.org>

Fixes scala#11713
Fixes scala#13668
@Kordyjan Kordyjan added this to the 3.2.1 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants