Skip to content

Commit

Permalink
Update doc on implicit resolution changes
Browse files Browse the repository at this point in the history
Update doc on implicit resolution changes to take the previous changes
in #5887 into account.
  • Loading branch information
odersky committed Feb 14, 2019
1 parent 0802f47 commit c3a7b23
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions docs/docs/reference/changed-features/implicit-resolution.md
Expand Up @@ -35,9 +35,26 @@ affect implicits on the language level.

This will now resolve the `implicitly` call to `j`, because `j` is nested
more deeply than `i`. Previously, this would have resulted in an
ambiguity error.
ambiguity error. The previous possibility of an implicit search failure
sure to _shadowing_ (where an implicit is hidden by a nested definition)
no longer applies.

3. The treatment of ambiguity errors has changed. If an ambiguity is encountered
3. Package prefixes no longer count towards the implicit scope of a type.
Example:

package p
implied a for A

object o {
implied b for B
type C
}

Then both `a` and `b` are visible as implicits at the point of the definition
of `type C`. However, a reference to `p.o.C` outside of package `p` will
have `b` in its implicit scope but not `a`.

4. The treatment of ambiguity errors has changed. If an ambiguity is encountered
in some recursive step of an implicit search, the ambiguity is propagated to the caller.
Example: Say you have the following definitions:

Expand Down Expand Up @@ -65,14 +82,14 @@ affect implicits on the language level.
which implements negation directly. For any query type `Q`: `Not[Q]` succeeds if and only if
the implicit search for `Q` fails.

4. The treatment of divergence errors has also changed. A divergent implicit is
5. The treatment of divergence errors has also changed. A divergent implicit is
treated as a normal failure, after which alternatives are still tried. This also makes
sense: Encountering a divergent implicit means that we assume that no finite
solution can be found on the given path, but another path can still be tried. By contrast
most (but not all) divergence errors in Scala 2 would terminate the implicit
search as a whole.

5. Scala-2 gives a lower level of priority to implicit conversions with call-by-name
6. Scala-2 gives a lower level of priority to implicit conversions with call-by-name
parameters relative to implicit conversions with call-by-value parameters. Dotty
drops this distinction. So the following code snippet would be ambiguous in Dotty:

Expand All @@ -81,7 +98,7 @@ affect implicits on the language level.
def buzz(y: A) = ???
buzz(1) // error: ambiguous

6. The rule for picking a _most specific_ alternative among a set of overloaded or implicit
7. The rule for picking a _most specific_ alternative among a set of overloaded or implicit
alternatives is refined to take the number of inferable parameters into account. All else
being equal, an alternative that takes more inferable parameters is taken to be more specific
than an alternative that takes fewer. The following paragraph in the SLS is affected by this change:
Expand Down

0 comments on commit c3a7b23

Please sign in to comment.