Skip to content

Commit

Permalink
Merge pull request #14775 from dotty-staging/fix-14675
Browse files Browse the repository at this point in the history
Document different handling of default arguments in overloading
  • Loading branch information
smarter committed Mar 25, 2022
2 parents c2c9b10 + bf72b7d commit 6f3fe05
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
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())

0 comments on commit 6f3fe05

Please sign in to comment.