Skip to content

Commit 6f3fe05

Browse files
authored
Merge pull request #14775 from dotty-staging/fix-14675
Document different handling of default arguments in overloading
2 parents c2c9b10 + bf72b7d commit 6f3fe05

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

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

+11-1
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 to a parameter of a method can 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

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1

tests/run/i14675.scala

+4
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)