Skip to content

Commit 5eceb36

Browse files
committed
Adapt docs
1 parent e60aa9e commit 5eceb36

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

docs/_docs/reference/changed-features/implicit-resolution.md

+32
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,35 @@ The new rules are as follows: An implicit `a` defined in `A` is more specific th
164164
Condition (*) is new. It is necessary to ensure that the defined relation is transitive.
165165

166166
[//]: # todo: expand with precise rules
167+
168+
**9.** The following change is currently enabled in `-source future`:
169+
170+
Implicit resolution now avoids generating recursive givens that can lead to an infinite loop at runtime. Here is an example:
171+
172+
```scala
173+
object Prices {
174+
opaque type Price = BigDecimal
175+
176+
object Price{
177+
given Ordering[Price] = summon[Ordering[BigDecimal]] // was error, now avoided
178+
}
179+
}
180+
```
181+
182+
Previously, implicit resolution would resolve the `summon` to the given in `Price`, leading to an infinite loop (a warning was issued in that case). We now use the underlying given in `BigDecimal` instead. We achieve that by adding the following rule for implicit search:
183+
184+
- When doing an implicit search while checking the implementation of a `given` definition `G` of the form
185+
```
186+
given ... = ....
187+
```
188+
discard all search results that lead back to `G` or to a given with the same owner as `G` that comes later in the source than `G`.
189+
190+
The new behavior is currently enabled in `source.future` and will be enabled at the earliest in Scala 3.6. For earlier source versions, the behavior is as
191+
follows:
192+
193+
- Scala 3.3: no change
194+
- Scala 3.4: A warning is issued where the behavior will change in 3.future.
195+
- Scala 3.5: An error is issued where the behavior will change in 3.future.
196+
197+
Old-style implicit definitions are unaffected by this change.
198+

docs/sidebar.yml

-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ subsection:
153153
- page: reference/experimental/cc.md
154154
- page: reference/experimental/purefuns.md
155155
- page: reference/experimental/tupled-function.md
156-
- page: reference/experimental/given-loop-prevention.md
157156
- page: reference/syntax.md
158157
- title: Language Versions
159158
index: reference/language-versions/language-versions.md

0 commit comments

Comments
 (0)