Skip to content

Add document and test for overload resolution #6134

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

Merged
merged 1 commit into from
Mar 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions docs/docs/reference/changed-features/overload-resolution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
layout: doc-page
title: "Changes in Overload Resolution"
---

Overload resolution in Dotty takes all argument blocks into account instead of
just the first argument block.

For example, the following code compiles in Dotty, while it results in an
ambiguous overload error in Scala2:

```Scala
def f(x: Int)(y: String): Int = 0
def f(x: Int)(y: Int): Int = 0

f(3)("") // ok
```

The following code compiles as well:

```Scala
def g(x: Int)(y: Int)(z: Int): Int = 0
def g(x: Int)(y: Int)(z: String): Int = 0

g(2)(3)(4) // ok
g(2)(3)("") // ok
```

This change is motivated by the new language feature [extension
methods](../contextual/extension-methods.html), where emerges the need to do
overload resolution based on additional argument blocks.
2 changes: 2 additions & 0 deletions docs/sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ sidebar:
url: docs/reference/changed-features/implicit-resolution.html
- title: Implicit Conversions
url: docs/reference/changed-features/implicit-conversions.html
- title: Overload Resolution
url: docs/reference/changed-features/overload-resolution.html
- title: Vararg Patterns
url: docs/reference/changed-features/vararg-patterns.html
- title: Pattern matching
Expand Down
14 changes: 14 additions & 0 deletions tests/pos/i6116.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Test {
def f(x: Int)(y: String): Int = ???
def f(x: Int)(y: Int): Int = ???

f(3)("") // ok
f(3)(4) // ok

def g(x: Int)(y: Int)(z: Int): Int = ???
def g(x: Int)(y: Int)(z: String): Int = ???

g(2)(3)(4) // ok
g(2)(3)("") // ok
}