Skip to content

Commit 5953f8b

Browse files
committed
Document different handling of default arguments in overloading
Document different handling of default arguments in overloading resolution relative to Scala-2. Fixes #14675
1 parent fdd43d7 commit 5953f8b

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

docs/_docs/reference/changed-features/overload-resolution.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ title: "Changes in Overload Resolution"
44
movedTo: https://docs.scala-lang.org/scala3/reference/changed-features/overload-resolution.html
55
---
66

7-
Overload resolution in Scala 3 improves on Scala 2 in two ways.
7+
Overload resolution in Scala 3 improves on Scala 2 in three ways.
88
First, it takes all argument lists into account instead of
99
just the first argument list.
1010
Second, it can infer parameter types of function values even if they
1111
are in the first argument list.
12+
Third, default arguments are no longer relevant for prioritization.
1213

1314
## Looking Beyond the First Argument List
1415

@@ -90,3 +91,12 @@ x => x match { case P1 => B1 ... case P_n => B_n }
9091
```
9192

9293
and is therefore also approximated with a `? => ?` type.
94+
95+
## Default Arguments Are No longer Relevant for Prioritization
96+
97+
In Scala 2 if among several applicative alternatives one alternative had default arguments, that alternative was dropped from consideration. This has the unfortunate
98+
side effect that adding a default parameter to a method can change render this method
99+
invisible in overloaded calls.
100+
101+
Scala 3 drops this distinction. Methods with default parameters are not treated
102+
to have lower priority than other methods.

tests/run/i14675.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1

tests/run/i14675.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def f(x: Int = 0): Int = 1
2+
def f(x: Int*): Int = 2
3+
4+
@main def Test = println(f())

0 commit comments

Comments
 (0)