Skip to content

Commit 5134e98

Browse files
authored
Merge pull request #8367 from robstoll/patch-30
doc(operators): typo and add import to examples
2 parents d943616 + 4922e7f commit 5134e98

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

docs/docs/reference/changed-features/operators.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Furthermore, a syntax change allows infix operators to be written on the left in
1010

1111
An `@alpha` annotation on a method definition defines an alternate name for the implementation of that method: Example:
1212
```scala
13+
import scala.annotation.alpha
14+
1315
object VecOps {
1416
@alpha("append") def (xs: Vec[T]) ++= [T] (ys: Vec[T]): Vec[T] = ...
1517
}
@@ -47,7 +49,7 @@ The `@alpha` annotation serves a dual purpose:
4749
5. Definitions with names in backticks that are not legal host platform names
4850
should have an `@alpha` annotation. Lack of such an annotation will raise a deprecation warning.
4951

50-
6. @alpha annotations must agree: If two definitions are members of an object or class with the same name and matching types, then either none of them has an `@alpha` annotation, or both have `@alpha` annotations with the same name.
52+
6. `@alpha` annotations must agree: If two definitions are members of an object or class with the same name and matching types, then either none of them has an `@alpha` annotation, or both have `@alpha` annotations with the same name.
5153

5254
7. There must be a one-to-one relationship between external and internal names:
5355
If two definitions are members of an object or class with matching types and both have `@alpha` annotations with the same external name, then their internal method names must also be the same.
@@ -56,6 +58,8 @@ The `@alpha` annotation serves a dual purpose:
5658

5759
An `@infix` annotation on a method definition allows using the method as an infix operation. Example:
5860
```scala
61+
import scala.annotation.alpha
62+
5963
trait MultiSet[T] {
6064

6165
@infix
@@ -70,13 +74,15 @@ trait MultiSet[T] {
7074
val s1, s2: MultiSet[Int]
7175

7276
s1 union s2 // OK
77+
s1 `union` s2 // also OK but unusual
7378
s1.union(s2) // also OK
7479

7580
s1.difference(s2) // OK
7681
s1 `difference` s2 // OK
7782
s1 difference s2 // gives a deprecation warning
7883

7984
s1 * s2 // OK
85+
s1 `*` s2 // also OK, but unusual
8086
s1.*(s2) // also OK, but unusual
8187
```
8288
Infix operations involving alphanumeric operators are deprecated, unless
@@ -91,7 +97,7 @@ any unicode character `c` for which `java.lang.Character.isIdentifierPart(c)` re
9197

9298
Infix operations involving symbolic operators are always allowed, so `@infix` is redundant for methods with symbolic names.
9399

94-
The @infix annotation can also be given to a type:
100+
The `@infix` annotation can also be given to a type:
95101
```
96102
@infix type or[X, Y]
97103
val x: String or Int = ...
@@ -118,15 +124,15 @@ The purpose of the `@infix` annotation is to achieve consistency across a code b
118124
@infix def (x: A) op (y1: B, y2: B): R // error: two parameters
119125
```
120126

121-
4. @infix annotations can also be given to type, trait or class definitions that have exactly two type parameters. An infix type like
127+
4. `@infix` annotations can also be given to type, trait or class definitions that have exactly two type parameters. An infix type like
122128

123129
```scala
124130
@infix type op[X, Y]
125131
```
126132

127133
can be applied using infix syntax, i.e. `A op B`.
128134

129-
5. To smooth migration to Scala 3.0, alphanumeric operations will only be deprecated from Scala 3.1 onwards,
135+
5. To smooth migration to Scala 3.0, alphanumeric operators will only be deprecated from Scala 3.1 onwards,
130136
or if the `-strict` option is given in Dotty/Scala 3.
131137

132138
## Syntax Change

0 commit comments

Comments
 (0)