diff --git a/docs/_docs/reference/changed-features/overload-resolution.md b/docs/_docs/reference/changed-features/overload-resolution.md index e6c929f7a2ef..acdf3e96a381 100644 --- a/docs/_docs/reference/changed-features/overload-resolution.md +++ b/docs/_docs/reference/changed-features/overload-resolution.md @@ -4,11 +4,12 @@ title: "Changes in Overload Resolution" movedTo: https://docs.scala-lang.org/scala3/reference/changed-features/overload-resolution.html --- -Overload resolution in Scala 3 improves on Scala 2 in two ways. +Overload resolution in Scala 3 improves on Scala 2 in three ways. First, it takes all argument lists into account instead of just the first argument list. Second, it can infer parameter types of function values even if they are in the first argument list. +Third, default arguments are no longer relevant for prioritization. ## Looking Beyond the First Argument List @@ -90,3 +91,12 @@ x => x match { case P1 => B1 ... case P_n => B_n } ``` and is therefore also approximated with a `? => ?` type. + +## Default Arguments Are No longer Relevant for Prioritization + +In Scala 2 if among several applicative alternatives one alternative had default arguments, that alternative was dropped from consideration. This has the unfortunate +side effect that adding a default to a parameter of a method can render this method +invisible in overloaded calls. + +Scala 3 drops this distinction. Methods with default parameters are not treated +to have lower priority than other methods. diff --git a/tests/run/i14675.check b/tests/run/i14675.check new file mode 100644 index 000000000000..d00491fd7e5b --- /dev/null +++ b/tests/run/i14675.check @@ -0,0 +1 @@ +1 diff --git a/tests/run/i14675.scala b/tests/run/i14675.scala new file mode 100644 index 000000000000..a776fe6d05ef --- /dev/null +++ b/tests/run/i14675.scala @@ -0,0 +1,4 @@ +def f(x: Int = 0): Int = 1 +def f(x: Int*): Int = 2 + +@main def Test = println(f())