Skip to content

Commit c2551b9

Browse files
authored
Merge pull request #6134 from dotty-staging/overload-doc
Add document and test for overload resolution
2 parents bb0a1ed + 180ab40 commit c2551b9

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
layout: doc-page
3+
title: "Changes in Overload Resolution"
4+
---
5+
6+
Overload resolution in Dotty takes all argument blocks into account instead of
7+
just the first argument block.
8+
9+
For example, the following code compiles in Dotty, while it results in an
10+
ambiguous overload error in Scala2:
11+
12+
```Scala
13+
def f(x: Int)(y: String): Int = 0
14+
def f(x: Int)(y: Int): Int = 0
15+
16+
f(3)("") // ok
17+
```
18+
19+
The following code compiles as well:
20+
21+
```Scala
22+
def g(x: Int)(y: Int)(z: Int): Int = 0
23+
def g(x: Int)(y: Int)(z: String): Int = 0
24+
25+
g(2)(3)(4) // ok
26+
g(2)(3)("") // ok
27+
```
28+
29+
This change is motivated by the new language feature [extension
30+
methods](../contextual/extension-methods.html), where emerges the need to do
31+
overload resolution based on additional argument blocks.

docs/sidebar.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ sidebar:
9999
url: docs/reference/changed-features/implicit-resolution.html
100100
- title: Implicit Conversions
101101
url: docs/reference/changed-features/implicit-conversions.html
102+
- title: Overload Resolution
103+
url: docs/reference/changed-features/overload-resolution.html
102104
- title: Vararg Patterns
103105
url: docs/reference/changed-features/vararg-patterns.html
104106
- title: Pattern matching

tests/pos/i6116.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Test {
2+
def f(x: Int)(y: String): Int = ???
3+
def f(x: Int)(y: Int): Int = ???
4+
5+
f(3)("") // ok
6+
f(3)(4) // ok
7+
8+
def g(x: Int)(y: Int)(z: Int): Int = ???
9+
def g(x: Int)(y: Int)(z: String): Int = ???
10+
11+
g(2)(3)(4) // ok
12+
g(2)(3)("") // ok
13+
}
14+

0 commit comments

Comments
 (0)