From 64feca3b4c9335aaef70a74e5654cfed49a95c87 Mon Sep 17 00:00:00 2001 From: Lucas Date: Thu, 25 May 2023 15:21:47 +0200 Subject: [PATCH 1/2] Refactor: Redirection to boundary/break instead of scala.util.control.NonLocalReturns [Cherry-picked 3502cef38aa6d396e737fda33f5bb7a1dfe988e4] --- .../dropped-features/nonlocal-returns.md | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/docs/_docs/reference/dropped-features/nonlocal-returns.md b/docs/_docs/reference/dropped-features/nonlocal-returns.md index 17b86f77ee56..e6490b7ca5bc 100644 --- a/docs/_docs/reference/dropped-features/nonlocal-returns.md +++ b/docs/_docs/reference/dropped-features/nonlocal-returns.md @@ -9,21 +9,17 @@ Returning from nested anonymous functions has been deprecated, and will produce 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`. -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: +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). -```scala -import scala.util.control.NonLocalReturns.* - -extension [T](xs: List[T]) - def has(elem: T): Boolean = returning { - for x <- xs do - if x == elem then throwReturn(true) - false - } +Example: -@main def test(): Unit = - val xs = List(1, 2, 3, 4, 5) - assert(xs.has(2) == xs.contains(2)) +```scala +import scala.util.boundary, boundary.break +def firstIndex[T](xs: List[T], elem: T): Int = + boundary: + for (x, i) <- xs.zipWithIndex do + if x == elem then break(i) + -1 ``` Note: compiler produces deprecation error on nonlocal returns only with `-source:future` option. From 252bc8087ad656b97beb1341abbaf673057b4c4c Mon Sep 17 00:00:00 2001 From: Chris Kipp Date: Fri, 26 May 2023 12:50:52 +0200 Subject: [PATCH 2/2] docs: remove empty "changes in type checking" page (#17494) This relates to https://github.com/lampepfl/dotty/issues/10759. Just as a general rule of thumb, I don't think we should have fully empty pages in documentation like this. It's not a great look to the outside world. [skip community_build] refs: https://github.com/lampepfl/dotty/issues/10759 [Cherry-picked a682211d70f8cb9f98d913f7550be244942c9688] --- docs/_docs/reference/changed-features/type-checking.md | 7 ------- docs/sidebar.yml | 1 - project/resources/referenceReplacements/sidebar.yml | 1 - .../scripts/expected-links/reference-expected-links.txt | 1 - 4 files changed, 10 deletions(-) delete mode 100644 docs/_docs/reference/changed-features/type-checking.md diff --git a/docs/_docs/reference/changed-features/type-checking.md b/docs/_docs/reference/changed-features/type-checking.md deleted file mode 100644 index 6f59b1a1c1c6..000000000000 --- a/docs/_docs/reference/changed-features/type-checking.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -layout: doc-page -title: "Changes in Type Checking" -nightlyOf: https://docs.scala-lang.org/scala3/reference/changed-features/type-checking.html ---- - -*** **TO BE FILLED IN** *** diff --git a/docs/sidebar.yml b/docs/sidebar.yml index 345134cf2e9b..30ad05d18cf1 100644 --- a/docs/sidebar.yml +++ b/docs/sidebar.yml @@ -92,7 +92,6 @@ subsection: - page: reference/changed-features/operators.md - page: reference/changed-features/wildcards.md - page: reference/changed-features/imports.md - - page: reference/changed-features/type-checking.md - page: reference/changed-features/type-inference.md - page: reference/changed-features/implicit-resolution.md - page: reference/changed-features/implicit-conversions.md diff --git a/project/resources/referenceReplacements/sidebar.yml b/project/resources/referenceReplacements/sidebar.yml index be67a0d6da99..de0f3d7bec2c 100644 --- a/project/resources/referenceReplacements/sidebar.yml +++ b/project/resources/referenceReplacements/sidebar.yml @@ -88,7 +88,6 @@ subsection: - page: reference/changed-features/operators.md - page: reference/changed-features/wildcards.md - page: reference/changed-features/imports.md - - page: reference/changed-features/type-checking.md - page: reference/changed-features/type-inference.md - page: reference/changed-features/implicit-resolution.md - page: reference/changed-features/implicit-conversions.md diff --git a/project/scripts/expected-links/reference-expected-links.txt b/project/scripts/expected-links/reference-expected-links.txt index a09737574c1d..0fbb84831e37 100644 --- a/project/scripts/expected-links/reference-expected-links.txt +++ b/project/scripts/expected-links/reference-expected-links.txt @@ -18,7 +18,6 @@ ./changed-features/pattern-matching.html ./changed-features/structural-types-spec.html ./changed-features/structural-types.html -./changed-features/type-checking.html ./changed-features/type-inference.html ./changed-features/vararg-splices.html ./changed-features/wildcards.html