From 56b2d42d31b412db624481d0cc55eeddfd28bb7b Mon Sep 17 00:00:00 2001 From: Aleksey Troitskiy Date: Fri, 25 Apr 2025 10:11:51 +0300 Subject: [PATCH] doc: make TypeTest example compiling (#23009) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Current example is not compiling: ```scala import scala.reflect.{ClassTag, TypeTest} val tt: TypeTest[Any, String] = new TypeTest[Any, String]: def unapply(s: Any): Option[s.type & String] = s match case s: String => Some(s) // compiler error Found: (s : String) Required: (s² : Any) & String case _ => None ``` https://scastie.scala-lang.org/road21/jq3j9XsUTdeshqbHxDXv3w [Cherry-picked 6c021c67a0e3fcc3b14e6c931686ff390b8b45c2] --- docs/_docs/reference/other-new-features/type-test.md | 2 +- docs/_spec/TODOreference/other-new-features/type-test.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/_docs/reference/other-new-features/type-test.md b/docs/_docs/reference/other-new-features/type-test.md index ec7a87230753..fb2a2e584711 100644 --- a/docs/_docs/reference/other-new-features/type-test.md +++ b/docs/_docs/reference/other-new-features/type-test.md @@ -63,7 +63,7 @@ We could create a type test at call site where the type test can be performed wi val tt: TypeTest[Any, String] = new TypeTest[Any, String]: def unapply(s: Any): Option[s.type & String] = s match - case s: String => Some(s) + case q: (s.type & String) => Some(q) case _ => None f[AnyRef, String]("acb")(using tt) diff --git a/docs/_spec/TODOreference/other-new-features/type-test.md b/docs/_spec/TODOreference/other-new-features/type-test.md index ec7a87230753..fb2a2e584711 100644 --- a/docs/_spec/TODOreference/other-new-features/type-test.md +++ b/docs/_spec/TODOreference/other-new-features/type-test.md @@ -63,7 +63,7 @@ We could create a type test at call site where the type test can be performed wi val tt: TypeTest[Any, String] = new TypeTest[Any, String]: def unapply(s: Any): Option[s.type & String] = s match - case s: String => Some(s) + case q: (s.type & String) => Some(q) case _ => None f[AnyRef, String]("acb")(using tt)