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/blog/_posts/2019-05-24-15th-dotty-milestone-release.md
+47-1Lines changed: 47 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -81,9 +81,55 @@ To smoothen the migration, the deprecation warnings will only be emitted if you
81
81
For more information, see the [documentation](http://dotty.epfl.ch/docs/reference/changed-features/operators.html#the-infix-annotation). Note that the `@alpha` annotation also described in the documentation is a work in progress and is not available in this release.
82
82
83
83
## `given` clause comes last
84
+
In the previous release, you could write something like this:
84
85
86
+
```scala
87
+
implied forString="foo"
88
+
deff(x: Int) given (y: String) (z: Int) = x + z
89
+
f(1)(3)
90
+
```
91
+
92
+
Now, however, `given` clauses must come last:
93
+
94
+
```scala
95
+
implied forString="foo"
96
+
deff(x: Int)(z: Int) given (y: String) = x + z
97
+
f(1)(3)
98
+
```
99
+
100
+
This change is done to reduce confusion when calling functions with mixed explicit and implied parameters.
101
+
102
+
## Type-safe Pattern Bindings
103
+
```scala
104
+
valxs:List[Any] =List(1, 2, 3)
105
+
val (x: String) :: _ = xs // error: pattern's type String is more specialized
106
+
// than the right hand side expression's type Any
107
+
```
108
+
109
+
The above code will fail with a compile-time error in Dotty 3.1 and in Dotty 3 with the `-strict` flag. In contrast, in Scala 2, the above would have compiled fine but failed on runtime with an exception.
110
+
111
+
Dotty compiler will allow such a pattern binding only if the pattern is *irrefutable* – that is, if the right-hand side conforms to the pattern's type. E.g. the following is OK:
112
+
113
+
```scala
114
+
valpair= (1, true)
115
+
val (x, y) = pair
116
+
```
117
+
118
+
If we want to force the pattern binding if the pattern is not irrefutable, we can do so with an annotation:
119
+
120
+
```scala
121
+
valfirst::rest : @unchecked = elems // OK
122
+
```
123
+
124
+
The same is implemented for pattern bindings in `for` expressions:
125
+
126
+
```scala
127
+
valelems:List[Any] =List((1, 2), "hello", (3, 4))
128
+
for ((x, y) <- elems) yield (y, x) // error: pattern's type (Any, Any) is more specialized
129
+
// than the right hand side expression's type Any
130
+
```
85
131
86
-
### Compatibility: the `@alpha` annotation
132
+
For the migration purposes, the above change will only take effect in Dotty 3.1 by default. You can use it from Dotty 3 with the `-strict` flag.
0 commit comments