@@ -29,7 +29,7 @@ affect implicits on the language level.
29
29
/*!*/ def f(implicit x: y.type) // error `y.type` not allowed as type of implicit
30
30
31
31
3 . Nesting is now taken into account for selecting an implicit.
32
- Consider for instance the following scenario
32
+ Consider for instance the following scenario:
33
33
34
34
def f(implicit i: C) = {
35
35
def g(implicit j: C) = {
@@ -41,4 +41,40 @@ affect implicits on the language level.
41
41
more deeply than ` i ` . Previously, this would have resulted in an
42
42
ambiguity error.
43
43
44
+ 4 . The treatment of ambiguity errors has changed. If an ambiguity is encountered
45
+ in some recursive step of an implicit search, the ambiguity is propagated to the caller.
46
+ Example: Say you have the following definitions:
47
+
48
+ class A
49
+ class B extends C
50
+ class C
51
+ implicit def a1: A
52
+ implicit def a2: A
53
+ implicit def b(implicit a: A): B
54
+ implicit def c: C
55
+
56
+ and the query ` implicitly[C] ` .
57
+
58
+ This query would now be classified as ambiguous. This makes sense, after all
59
+ there are two possible solutions, ` b(a1) ` and ` b(a2) ` , neither of which is better
60
+ than the other and both of which are better than the third solution, ` c ` .
61
+ By contrast, Scala 2 would have rejected the search for ` A ` as
62
+ ambiguous, and subsequently have classified the query ` b(implicitly[A]) ` as a normal fail,
63
+ which means that the alternative ` c ` would be chosen as solution!
64
+
65
+ Scala 2's somewhat puzzling behavior with respect to ambiguity has been exploited to implement
66
+ the analogue of a "negated" search in implicit resolution, where a query ` Q1 ` fails if some
67
+ other query ` Q2 ` succeeds and ` Q1 ` succeeds if ` Q2 ` fails. With the new cleaned up behavior
68
+ these techniques no longer work. But there is now a new special type ` scala.implicits.Not `
69
+ which implements negation directly. For any query type ` Q ` : ` Not[Q] ` succeeds if and only if
70
+ the implicit search for ` Q ` fails.
71
+
72
+ 5 . The treatment of divergence errors has also changed. A divergent implicit is
73
+ treated as a normal failure, after which alternatives are still tried. This also makes
74
+ sense: Encountering a divergent implicit means that we assume that no finite
75
+ solution can be found on the given path, but another path can still be tried. By contrast
76
+ most (but not all) divergence errors in Scala 2 would terminate the implicit
77
+ search as a whole.
78
+
79
+
44
80
[ //] : # todo: expand with precise rules
0 commit comments