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/operators.md
+20-21Lines changed: 20 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -5,20 +5,19 @@ title: Rules for Operators
5
5
6
6
The rules for infix operators have changed in some parts:
7
7
8
-
First, an alphanumeric method can be used as an infix operator only if its definition carries an `@infix`annotation. Second, it is recommended (but not enforced) to
8
+
First, an alphanumeric method can be used as an infix operator only if its definition carries an `infix`modifier. Second, it is recommended (but not enforced) to
9
9
augment definitions of symbolic operators with `@targetName` annotations. Finally,
10
10
a syntax change allows infix operators to be written on the left in a multi-line expression.
11
11
12
-
## The @infix Annotation
12
+
## The `infix` Modifier
13
13
14
-
An `@infix`annotation on a method definition allows using the method as an infix operation. Example:
14
+
An `infix`modifier on a method definition allows using the method as an infix operation. Example:
15
15
```scala
16
-
importscala.annotation.{infix, targetName}
16
+
importscala.annotation.targetName
17
17
18
18
traitMultiSet[T] {
19
19
20
-
@infix
21
-
defunion(other: MultiSet[T]):MultiSet[T]
20
+
infixdefunion(other: MultiSet[T]):MultiSet[T]
22
21
23
22
defdifference(other: MultiSet[T]):MultiSet[T]
24
23
@@ -43,46 +42,46 @@ s1.*(s2) // also OK, but unusual
43
42
Infix operations involving alphanumeric operators are deprecated, unless
44
43
one of the following conditions holds:
45
44
46
-
- the operator definition carries an `@infix`annotation, or
45
+
- the operator definition carries an `infix`modifier, or
47
46
- the operator was compiled with Scala 2, or
48
47
- the operator is followed by an opening brace.
49
48
50
49
An alphanumeric operator is an operator consisting entirely of letters, digits, the `$` and `_` characters, or
51
50
any unicode character `c` for which `java.lang.Character.isIdentifierPart(c)` returns `true`.
52
51
53
-
Infix operations involving symbolic operators are always allowed, so `@infix` is redundant for methods with symbolic names.
52
+
Infix operations involving symbolic operators are always allowed, so `infix` is redundant for methods with symbolic names.
54
53
55
-
The `@infix`annotation can also be given to a type:
54
+
The `infix`modifier can also be given to a type:
56
55
```
57
-
@infix type or[X, Y]
56
+
infix type or[X, Y]
58
57
val x: String or Int = ...
59
58
```
60
59
61
60
### Motivation
62
61
63
-
The purpose of the `@infix`annotation is to achieve consistency across a code base in how a method or type is applied. The idea is that the author of a method decides whether that method should be applied as an infix operator or in a regular application. Use sites then implement that decision consistently.
62
+
The purpose of the `infix`modifier is to achieve consistency across a code base in how a method or type is applied. The idea is that the author of a method decides whether that method should be applied as an infix operator or in a regular application. Use sites then implement that decision consistently.
64
63
65
64
### Details
66
65
67
-
1.`@infix` is defined in package `scala.annotation`.
66
+
1.`infix` is a soft modifier. It is treated as a normal identifier except when in modifier position.
68
67
69
-
2. If a method overrides another, their infix annotations must agree. Either both are annotated with `@infix`, or none of them are.
68
+
2. If a method overrides another, their infix annotations must agree. Either both are annotated with `infix`, or none of them are.
70
69
71
-
3.`@infix`annotations can be given to method definitions. The first non-receiver parameter list of an `@infix` method must define exactly one parameter. Examples:
70
+
3.`infix`modifiers can be given to method definitions. The first non-receiver parameter list of an `infix` method must define exactly one parameter. Examples:
72
71
73
72
```scala
74
-
@infix defop(x: S):R// ok
75
-
@infix defop[T](x: T)(y: S):R// ok
76
-
@infix defop[T](x: T, y: S):R// error: two parameters
73
+
infixdefop(x: S):R// ok
74
+
infixdefop[T](x: T)(y: S):R// ok
75
+
infixdefop[T](x: T, y: S):R// error: two parameters
77
76
78
-
@infix def (x: A) op (y: B):R// ok
79
-
@infix def (x: A) op (y1: B, y2: B):R// error: two parameters
77
+
infixdef (x: A) op (y: B):R// ok
78
+
infixdef (x: A) op (y1: B, y2: B):R// error: two parameters
80
79
```
81
80
82
-
4. `@infix` annotations can also be giventotype, traitorclassdefinitions that have exactly two typeparameters. Aninfixtypelike
81
+
4. `infix` modifiers can also be giventotype, traitorclassdefinitions that have exactly two typeparameters. Aninfixtypelike
Copy file name to clipboardExpand all lines: docs/docs/reference/features-classification.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -73,7 +73,7 @@ These constructs are restricted to make the language safer.
73
73
-[Given Imports](contextual/import-delegate.md): implicits now require a special form of import, to make the import clearly visible.
74
74
-[Type Projection](dropped-features/type-projection.md): only classes can be used as prefix `C` of a type projection `C#A`. Type projection on abstract types is no longer supported since it is unsound.
75
75
-[Multiversal Equality](contextual/multiversal-equality.md) implements an "opt-in" scheme to rule out nonsensical comparisons with `==` and `!=`.
makes method application syntax uniform across code bases.
78
78
79
79
Unrestricted implicit conversions continue to be available in Scala 3.0, but will be deprecated and removed later. Unrestricted versions of the other constructs in the list above are available only under `-source 3.0-migration`.
Copy file name to clipboardExpand all lines: docs/docs/reference/overview.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -58,7 +58,7 @@ These constructs are restricted to make the language safer.
58
58
-[Given Imports](contextual/given-imports.md): implicits now require a special form of import, to make the import clearly visible.
59
59
-[Type Projection](dropped-features/type-projection.md): only classes can be used as prefix `C` of a type projection `C#A`. Type projection on abstract types is no longer supported since it is unsound.
60
60
-[Multiversal Equality](contextual/multiversal-equality.md) implements an "opt-in" scheme to rule out nonsensical comparisons with `==` and `!=`.
make method application syntax uniform across code bases.
63
63
64
64
Unrestricted implicit conversions continue to be available in Scala 3.0, but will be deprecated and removed later. Unrestricted versions of the other constructs in the list above are available only under `-source 3.0-migration`.
0 commit comments