Skip to content

Commit 928e01a

Browse files
authored
Merge pull request #10532 from dotty-staging/fix-10500
Fix infix docs
2 parents ed93a48 + 3ef80b2 commit 928e01a

File tree

4 files changed

+24
-26
lines changed

4 files changed

+24
-26
lines changed

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

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@ title: Rules for Operators
55

66
The rules for infix operators have changed in some parts:
77

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
99
augment definitions of symbolic operators with `@targetName` annotations. Finally,
1010
a syntax change allows infix operators to be written on the left in a multi-line expression.
1111

12-
## The @infix Annotation
12+
## The `infix` Modifier
1313

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:
1515
```scala
16-
import scala.annotation.{infix, targetName}
16+
import scala.annotation.targetName
1717

1818
trait MultiSet[T] {
1919

20-
@infix
21-
def union(other: MultiSet[T]): MultiSet[T]
20+
infix def union(other: MultiSet[T]): MultiSet[T]
2221

2322
def difference(other: MultiSet[T]): MultiSet[T]
2423

@@ -43,46 +42,46 @@ s1.*(s2) // also OK, but unusual
4342
Infix operations involving alphanumeric operators are deprecated, unless
4443
one of the following conditions holds:
4544

46-
- the operator definition carries an `@infix` annotation, or
45+
- the operator definition carries an `infix` modifier, or
4746
- the operator was compiled with Scala 2, or
4847
- the operator is followed by an opening brace.
4948

5049
An alphanumeric operator is an operator consisting entirely of letters, digits, the `$` and `_` characters, or
5150
any unicode character `c` for which `java.lang.Character.isIdentifierPart(c)` returns `true`.
5251

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.
5453

55-
The `@infix` annotation can also be given to a type:
54+
The `infix` modifier can also be given to a type:
5655
```
57-
@infix type or[X, Y]
56+
infix type or[X, Y]
5857
val x: String or Int = ...
5958
```
6059

6160
### Motivation
6261

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.
6463

6564
### Details
6665

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.
6867

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.
7069

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:
7271

7372
```scala
74-
@infix def op(x: S): R // ok
75-
@infix def op[T](x: T)(y: S): R // ok
76-
@infix def op[T](x: T, y: S): R // error: two parameters
73+
infix def op(x: S): R // ok
74+
infix def op[T](x: T)(y: S): R // ok
75+
infix def op[T](x: T, y: S): R // error: two parameters
7776

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+
infix def (x: A) op (y: B): R // ok
78+
infix def (x: A) op (y1: B, y2: B): R // error: two parameters
8079
```
8180

82-
4. `@infix` annotations can also be given to type, trait or class definitions that have exactly two type parameters. An infix type like
81+
4. `infix` modifiers can also be given to type, trait or class definitions that have exactly two type parameters. An infix type like
8382

8483
```scala
85-
@infix type op[X, Y]
84+
infix type op[X, Y]
8685
```
8786

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

docs/docs/reference/features-classification.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ These constructs are restricted to make the language safer.
7373
- [Given Imports](contextual/import-delegate.md): implicits now require a special form of import, to make the import clearly visible.
7474
- [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.
7575
- [Multiversal Equality](contextual/multiversal-equality.md) implements an "opt-in" scheme to rule out nonsensical comparisons with `==` and `!=`.
76-
- [@infix](https://github.com/lampepfl/dotty/pull/5975)
76+
- [infix](https://github.com/lampepfl/dotty/pull/5975)
7777
makes method application syntax uniform across code bases.
7878

7979
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`.

docs/docs/reference/metaprogramming/inline.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ val multiplication: 3 * 5 = 15
500500

501501
Many of these singleton operation types are meant to be used infix (as in [SLS §
502502
3.2.8](https://www.scala-lang.org/files/archive/spec/2.12/03-types.html#infix-types)),
503-
and are annotated with [`@infix`](scala.annotation.infix) accordingly.
503+
and are annotated accordingly with [`infix`] modifiers.
504504

505505
Since type aliases have the same precedence rules as their term-level
506506
equivalents, the operations compose with the expected precedence rules:
@@ -518,9 +518,8 @@ match type can dispatch to the correct implementation:
518518

519519
```scala
520520
import scala.compiletime.ops._
521-
import scala.annotation.infix
522521

523-
@infix type +[X <: Int | String, Y <: Int | String] = (X, Y) match {
522+
infix type +[X <: Int | String, Y <: Int | String] = (X, Y) match {
524523
case (Int, Int) => int.+[X, Y]
525524
case (String, String) => string.+[X, Y]
526525
}

docs/docs/reference/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ These constructs are restricted to make the language safer.
5858
- [Given Imports](contextual/given-imports.md): implicits now require a special form of import, to make the import clearly visible.
5959
- [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.
6060
- [Multiversal Equality](contextual/multiversal-equality.md) implements an "opt-in" scheme to rule out nonsensical comparisons with `==` and `!=`.
61-
- [@infix annotations](changed-features/operators.md)
61+
- [infix](changed-features/operators.md)
6262
make method application syntax uniform across code bases.
6363

6464
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

Comments
 (0)