diff --git a/docs/docs/reference/changed-features/overload-resolution.md b/docs/docs/reference/changed-features/overload-resolution.md new file mode 100644 index 000000000000..c96731cdc4b6 --- /dev/null +++ b/docs/docs/reference/changed-features/overload-resolution.md @@ -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. diff --git a/docs/sidebar.yml b/docs/sidebar.yml index aeb8d4e8d935..ca7e91da3f7e 100644 --- a/docs/sidebar.yml +++ b/docs/sidebar.yml @@ -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 diff --git a/tests/pos/i6116.scala b/tests/pos/i6116.scala new file mode 100644 index 000000000000..159f132b2cb2 --- /dev/null +++ b/tests/pos/i6116.scala @@ -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 +} +