Skip to content

Eta expanding overloaded method with different type parameters selects an arbitrary overload #10850

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

Open
martijnhoekstra opened this issue Apr 26, 2018 · 2 comments
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) should not compile
Milestone

Comments

@martijnhoekstra
Copy link

def overloaded[A](a: A): A = a
def overloaded[A, B](a: A, b: B): A = a

def f = overloaded _

compiles in scala 2.12

In dotty this results in

|Ambiguous overload. The overloaded alternatives of method overloaded in object Test with types
| [A, B](a: A, b: B): A
| [A](a: A): A
|both match expected type ?

I expected the same behaviour in scala

@som-snytt
Copy link

This is the old chestnut where the two-parameter method is more specific because you can invoke the one-parameter method with two args by auto-tupling (but the converse is not true). Dotty is stingier with tupling, hence dotty-tupling.

@martijnhoekstra
Copy link
Author

@som-snytt way to un-minimize my test-case.

The original issue was, I believe, some variation of

type A
type B
type C
type D

def f: ((A, B) => C) => D = ???
def g = f.compose(Function.uncurried)

resulting in

polymorphic expression cannot be instantiated to expected type;
 found   : [a1, a2, a3, a4, a5, b](a1 => (a2 => (a3 => (a4 => (a5 => b))))) => ((a1, a2, a3, a4, a5) => b)
 required: ? => ((A, B) => C)

semi-minimized to val h = Function.uncurried _ compiling, and selecting an overload seemingly arbitrarily. Close and re-open with the other test-case? Or is this actually the same "works as expected (but only by people who know how it actually works, which isn't entirely intuitive, and possibly unspecced)"?

possibly related (and untested against) scala/scala#6275 and

possible duplicate of #3583

Sounds like something @adriaanm knows.

@SethTisue SethTisue added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label Feb 9, 2023
@SethTisue SethTisue added this to the Backlog milestone Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) should not compile
Projects
None yet
Development

No branches or pull requests

3 participants