Skip to content

Document different handling of default arguments in overloading #14775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 25, 2022
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())