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/2020-11-09-scala3-m1.md
+44-1Lines changed: 44 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ November 2020 brings an important milestone for Scala 3 – the release of Scala
9
9
10
10
Once 3.0.0 release candidate is out, no new features or breaking changes will take place on 3.0.x – it will only be updated for bug fixes. However, we are going to continue the work on making the language better and to test out our research in it. These changes will end up in Scala only as of 3.1.0.
11
11
12
-
For now though, our teams are focusing the efforts on getting done with the remainder of the 40-something projects that we planned for the upcoming release back in July 2020. Many of them are already completed. Those that aren't yet – get revised and re-planned. With the current global uncertainty and with the scale of the project, cannot be certain, but we believe we have a reasonable chance of releasing 3.0.0-RC1 by Christmas.
12
+
For now though, our teams are focusing the efforts on getting done with the remainder of the 40-something projects that we planned for the upcoming release back in July 2020. Many of them are already completed. Those that aren't yet – get revised and re-planned. With the current global uncertainty and with the scale of the project, we cannot be certain, but we believe we have a reasonable chance of releasing 3.0.0-RC1 by Christmas.
13
13
14
14
Below, you can find a short summary of the changes that took place during between the 0.27.0-RC1 and 3.0.0-M1 releases.
15
15
@@ -80,6 +80,49 @@ import p.given
80
80
81
81
This change was implemented by PR [#9949](https://github.com/lampepfl/dotty/pull/9949).
82
82
83
+
# Final API for enumerations
84
+
`enum` definitions are now released in their final design. since `0.27.0-RC1` we have made the following changes:
85
+
86
+
For the enum definition of Option:
87
+
```scala
88
+
enumOpt[+T] {
89
+
caseSm(value: T)
90
+
caseNn
91
+
}
92
+
```
93
+
we will now generate on the companion objects of class cases `apply` and `copy` methods with the precise subtype:
94
+
```scala
95
+
objectSm {
96
+
...
97
+
defapply[T](value: T):Sm[T]
98
+
...
99
+
}
100
+
```
101
+
however expressions that call `apply` or `copy` will be widened to the parent enum type unless the precise type is expected, as we see here:
102
+
```scala
103
+
scala>Sm(23)
104
+
valres0:Opt[Int] =Sm(23)
105
+
106
+
scala>valsm:Sm[23] =Sm(23)
107
+
valsm:Opt.Sm[23] =Sm(23)
108
+
```
109
+
Previously, when an enumeration declared cases with value parameters, such as `Opt.Sm`, then the `Opt.values` array would no longer have indexes that match the enum case ordinals. We feel that this is problematic, so the `values` and `valueOf` methods will only be generated when an enum has exclusively singleton cases.
110
+
111
+
If an enumeration adds a case with value parameters, then consumers will recieve an error that explains why `values` has been removed.
112
+
```scala
113
+
scala>Opt.values
114
+
1|Opt.values
115
+
|^^^^^^^^^^
116
+
|value values is not a member of objectOpt.
117
+
|AlthoughclassOpt is an enum, it has non-singleton cases,
118
+
|meaning a values array is not defined
119
+
```
120
+
For code that previously relied upon `values` to lookup singleton cases, we now provide an optimised method `fromOrdinal` that reflects singleton values. This method is always generated:
121
+
```scala
122
+
scala>Opt.fromOrdinal(1)
123
+
valres1:Opt[?] =Nn
124
+
```
125
+
83
126
# Keep `@alpha` optional for operators
84
127
Following the discussion on [contributors](https://contributors.scala-lang.org/t/the-alpha-notation/4583), we now keep `@alpha` optional for operators. The checking behavior is still available when compiling with the `-Yrequire-alpha`.
0 commit comments