From 180ab409f9a2c165b7ef7d53f12b95b3076be559 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Thu, 21 Mar 2019 10:40:18 +0100 Subject: [PATCH] Add document and test for overload resolution --- .../changed-features/overload-resolution.md | 31 +++++++++++++++++++ docs/sidebar.yml | 2 ++ tests/pos/i6116.scala | 14 +++++++++ 3 files changed, 47 insertions(+) create mode 100644 docs/docs/reference/changed-features/overload-resolution.md create mode 100644 tests/pos/i6116.scala 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 +} +