Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion docs/_docs/reference/changed-features/overload-resolution.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
1 change: 1 addition & 0 deletions tests/run/i14675.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
4 changes: 4 additions & 0 deletions tests/run/i14675.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def f(x: Int = 0): Int = 1
def f(x: Int*): Int = 2

@main def Test = println(f())