question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

position of using clause prevents overloaded extension method being picked

See original GitHub issue

Compiler version

3.0.0-RC1

Minimized code and output

extension [T1](x: T1)(using Numeric[T1])
  def combine[T2](y: T2)(using Numeric[T2]) = ???
  def combine(y: String) = ???

val res = 100.combine(200)
//        ^^^^^^^^^^^
//    value combine is not a member of Int.
//    An extension method was tried, but could not be fully constructed:
//
//        combine()    failed with
//
//            value combine: <overloaded combine> does not take parameters

Expectation : should work, as when we move using to the end of the parameter list:

extension [T1](x: T1)
  def combine[T2](y: T2)(using Numeric[T2], Numeric[T1]) = ???
  def combine(y: String) = ???

val res = 100.combine(200)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
rjollycommented, Mar 15, 2021

What’s disturbing is that with non-extensions it succeeds:

def combine[T1,T2](x: T1)(using Numeric[T1])(y: T2)(using Numeric[T2]) = ???
def combine[T1](x: T1)(using Numeric[T1])(y: String) = ???

val res = combine(100)(200)

So it seems we’re not far from the goal.

1reaction
som-snyttcommented, Oct 17, 2021

Also extension with overload, using: https://github.com/lampepfl/dotty/issues/13668

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is my Extension Method overload not preferred? [duplicate]
This is pretty clear that an attempt is made to bind an extension method only if the overload resolution process fails to find...
Read more >
Extension method call resolves to not-most-specific overload
By design, C# resolves overloads, including extension methods, primarily based on "namespace distance". Eric Lippert wrote an excellent blog ...
Read more >
Extension Methods - C# Programming Guide - Microsoft Learn
Extension methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the ...
Read more >
All C# Extension Methods - ExtensionMethod.NET
I provided 2 overloads of this method. One of them accepts a separator and the other uses comma "," as default separator. Also...
Read more >
2 CFR Part 200 -- Uniform Administrative Requirements, Cost ...
Disallowed costs means those charges to a Federal award that the Federal awarding agency or pass-through entity determines to be unallowable, in accordance ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found