File tree 2 files changed +5
-7
lines changed
docs/docs/reference/other-new-features
library/src/scala/reflect
2 files changed +5
-7
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ title: "TypeTest"
6
6
TypeTest
7
7
--------
8
8
9
- ` TypeTest ` provides the a replacement for ` ClassTag.unapply ` where the type of the argument is generalized.
9
+ ` TypeTest ` provides a replacement for ` ClassTag.unapply ` where the type of the argument is generalized.
10
10
` TypeTest.unapply ` will return ` Some(x.asInstanceOf[Y]) ` if ` x ` conforms to ` Y ` , otherwise it returns ` None ` .
11
11
12
12
``` scala
@@ -15,7 +15,7 @@ trait TypeTest[-S, T] extends Serializable {
15
15
}
16
16
```
17
17
18
- Just like ` ClassTag ` used to to , it can be used to perform type checks in patterns.
18
+ Just like ` ClassTag ` used to do , it can be used to perform type checks in patterns.
19
19
20
20
``` scala
21
21
type X
Original file line number Diff line number Diff line change 1
1
package scala .reflect
2
2
3
3
/** A `TypeTest[S, T] contains the logic needed to know at runtime if a value of
4
- * type `S` can be downcased to `T`.
4
+ * type `S` can be downcasted to `T`.
5
5
*
6
6
* If a pattern match is performed on a term of type `s: S` that is uncheckable with `s.isInstanceOf[T]` and
7
7
* the pattern are of the form:
8
8
* - `t: T`
9
9
* - `t @ X()` where the `X.unapply` has takes an argument of type `T`
10
- * then a given instance of `TypeTest[S, T]` is summoned and used to performed the test.
11
- *
12
- * Note: This is replacemet for `ClassTag.unapply` that can be sound for path dependent types
10
+ * then a given instance of `TypeTest[S, T]` is summoned and used to perform the test.
13
11
*/
14
12
@ scala.annotation.implicitNotFound(msg = " No TypeTest available for [${S}, ${T}]" )
15
13
trait TypeTest [- S , T ] extends Serializable {
16
14
17
15
/** A TypeTest[S, T] can serve as an extractor that matches only S of type T.
18
16
*
19
17
* The compiler tries to turn unchecked type tests in pattern matches into checked ones
20
- * by wrapping a `(_: T)` type pattern as `tt(_: T)`, where `ct ` is the `TypeTest[S, T]` instance.
18
+ * by wrapping a `(_: T)` type pattern as `tt(_: T)`, where `tt ` is the `TypeTest[S, T]` instance.
21
19
* Type tests necessary before calling other extractors are treated similarly.
22
20
* `SomeExtractor(...)` is turned into `tt(SomeExtractor(...))` if `T` in `SomeExtractor.unapply(x: T)`
23
21
* is uncheckable, but we have an instance of `TypeTest[S, T]`.
You can’t perform that action at this time.
0 commit comments