You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/reference/changed-features/pattern-bindings.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ From Scala 3.1 on, type checking rules will be tightened so that errors are repo
12
12
13
13
```scala
14
14
valxs:List[Any] =List(1, 2, 3)
15
-
val (x: String) :: _ xs // error: pattern's type String is more specialized
15
+
val (x: String) :: _ = xs// error: pattern's type String is more specialized
16
16
// than the right hand side expression's type Any
17
17
```
18
18
This code gives a compile-time error in Scala 3.1 (and also in Scala 3.0 under the `-strict` setting) whereas it will fail at runtime with a `ClassCastException` in Scala 2. In Scala 3.1, a pattern binding is only allowed if the pattern is _irrefutable_, that is, if the right-hand side's type conforms to the pattern's type. For instance, the following is OK:
0 commit comments