Skip to content

Commit 0833483

Browse files
authored
Backport "Sync with the stable documentation branch" to LTS (#18943)
Backports #17586 to the LTS branch. PR submitted by the release tooling.
2 parents f2d5539 + 252bc80 commit 0833483

File tree

5 files changed

+9
-23
lines changed

5 files changed

+9
-23
lines changed

docs/_docs/reference/changed-features/type-checking.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/_docs/reference/dropped-features/nonlocal-returns.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,17 @@ Returning from nested anonymous functions has been deprecated, and will produce
99

1010
Nonlocal returns are implemented by throwing and catching `scala.runtime.NonLocalReturnException`-s. This is rarely what is intended by the programmer. It can be problematic because of the hidden performance cost of throwing and catching exceptions. Furthermore, it is a leaky implementation: a catch-all exception handler can intercept a `NonLocalReturnException`.
1111

12-
A drop-in library replacement is provided in [`scala.util.control.NonLocalReturns`](https://scala-lang.org/api/3.x/scala/util/control/NonLocalReturns$.html). Example:
12+
A better alternative to nonlocal returns and also the `scala.util.control.Breaks` API is provided by [`scala.util.boundary` and `boundary.break`](http://dotty.epfl.ch/api/scala/util/boundary$.html).
1313

14-
```scala
15-
import scala.util.control.NonLocalReturns.*
16-
17-
extension [T](xs: List[T])
18-
def has(elem: T): Boolean = returning {
19-
for x <- xs do
20-
if x == elem then throwReturn(true)
21-
false
22-
}
14+
Example:
2315

24-
@main def test(): Unit =
25-
val xs = List(1, 2, 3, 4, 5)
26-
assert(xs.has(2) == xs.contains(2))
16+
```scala
17+
import scala.util.boundary, boundary.break
18+
def firstIndex[T](xs: List[T], elem: T): Int =
19+
boundary:
20+
for (x, i) <- xs.zipWithIndex do
21+
if x == elem then break(i)
22+
-1
2723
```
2824

2925
Note: compiler produces deprecation error on nonlocal returns only with `-source:future` option.

docs/sidebar.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ subsection:
9292
- page: reference/changed-features/operators.md
9393
- page: reference/changed-features/wildcards.md
9494
- page: reference/changed-features/imports.md
95-
- page: reference/changed-features/type-checking.md
9695
- page: reference/changed-features/type-inference.md
9796
- page: reference/changed-features/implicit-resolution.md
9897
- page: reference/changed-features/implicit-conversions.md

project/resources/referenceReplacements/sidebar.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ subsection:
8888
- page: reference/changed-features/operators.md
8989
- page: reference/changed-features/wildcards.md
9090
- page: reference/changed-features/imports.md
91-
- page: reference/changed-features/type-checking.md
9291
- page: reference/changed-features/type-inference.md
9392
- page: reference/changed-features/implicit-resolution.md
9493
- page: reference/changed-features/implicit-conversions.md

project/scripts/expected-links/reference-expected-links.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
./changed-features/pattern-matching.html
1919
./changed-features/structural-types-spec.html
2020
./changed-features/structural-types.html
21-
./changed-features/type-checking.html
2221
./changed-features/type-inference.html
2322
./changed-features/vararg-splices.html
2423
./changed-features/wildcards.html

0 commit comments

Comments
 (0)