Skip to content

Commit ffa59c8

Browse files
authored
Merge pull request #11427 from ShapelessCat/fix-minor-issues-in-docs
Fix docs
2 parents 1492745 + a1fdf1e commit ffa59c8

File tree

12 files changed

+54
-40
lines changed

12 files changed

+54
-40
lines changed

docs/docs/reference/changed-features/match-syntax.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ The syntactical precedence of match expressions has been changed.
1111
```scala
1212
xs match {
1313
case Nil => "empty"
14-
case x :: xs1 => "nonempty"
14+
case _ => "nonempty"
1515
} match {
16-
case "empty" => 0
16+
case "empty" => 0
1717
case "nonempty" => 1
1818
}
1919
```
@@ -23,7 +23,7 @@ The syntactical precedence of match expressions has been changed.
2323
```scala
2424
xs match
2525
case Nil => "empty"
26-
case x :: xs1 => "nonempty"
26+
case _ => "nonempty"
2727
match
2828
case "empty" => 0
2929
case "nonempty" => 1
@@ -34,7 +34,7 @@ The syntactical precedence of match expressions has been changed.
3434
```scala
3535
if xs.match
3636
case Nil => false
37-
case _ => true
37+
case _ => true
3838
then "nonempty"
3939
else "empty"
4040
```
@@ -46,7 +46,7 @@ The syntactical precedence of match expressions has been changed.
4646

4747
The new syntax of match expressions is as follows.
4848

49-
```
49+
```ebnf
5050
InfixExpr ::= ...
5151
| InfixExpr MatchClause
5252
SimpleExpr ::= ...

docs/docs/reference/changed-features/vararg-splices.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ The syntax of vararg splices in patterns and function arguments has changed. The
77

88
```scala
99
val arr = Array(0, 1, 2, 3)
10-
val lst = List(arr*) // vararg splice argument
10+
val lst = List(arr*) // vararg splice argument
1111
lst match
12-
case List(0, 1, xs*) => println(xs) // binds xs to Seq(2, 3)
13-
case List(1, _*) => // wildcard pattern
12+
case List(0, 1, xs*) => println(xs) // binds xs to Seq(2, 3)
13+
case List(1, _*) => // wildcard pattern
1414
```
1515

1616
The old syntax for splice arguments will be phased out.
1717

1818
```scala
19-
/*!*/ val lst = List(arr: _*) // syntax error
19+
/*!*/ val lst = List(arr: _*) // syntax error
2020
lst match
21-
case List(1, 2, xs @ _*) // ok, equivalent to `xs*`
21+
case List(0, 1, xs @ _*) // ok, equivalent to `xs*`
2222
```
2323

2424
## Syntax
2525

26-
```
26+
```ebnf
2727
ArgumentPatterns ::= ‘(’ [Patterns] ‘)’
2828
| ‘(’ [Patterns ‘,’] Pattern2 ‘*’ ‘)’
2929
@@ -37,6 +37,3 @@ To enable cross compilation between Scala 2 and Scala 3, the compiler will
3737
accept both the old and the new syntax. Under the `-source future` setting, an error
3838
will be emitted when the old syntax is encountered. An automatic rewrite from old
3939
to new syntax is offered under `-source future-migration`.
40-
41-
42-

docs/docs/reference/contextual/derivation.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ enum Opt[+T] derives Eq:
279279
case Sm(t: T)
280280
case Nn
281281

282-
@main def test =
282+
@main def test(): Unit =
283283
import Opt.*
284284
val eqoi = summon[Eq[Opt[Int]]]
285285
assert(eqoi.eqv(Sm(23), Sm(23)))
@@ -312,6 +312,7 @@ As a third example, using a higher level library such as Shapeless the type clas
312312
given eqSum[A](using inst: => K0.CoproductInstances[Eq, A]): Eq[A] with
313313
def eqv(x: A, y: A): Boolean = inst.fold2(x, y)(false)(
314314
[t] => (eqt: Eq[t], t0: t, t1: t) => eqt.eqv(t0, t1)
315+
)
315316

316317
given eqProduct[A](using inst: K0.ProductInstances[Eq, A]): Eq[A] with
317318
def eqv(x: A, y: A): Boolean = inst.foldLeft2(x, y)(true: Boolean)(
@@ -344,7 +345,7 @@ hand side of this definition in the same way as an instance defined in ADT compa
344345

345346
### Syntax
346347

347-
```
348+
```ebnf
348349
Template ::= InheritClauses [TemplateBody]
349350
EnumDef ::= id ClassConstr InheritClauses EnumBody
350351
InheritClauses ::= [‘extends’ ConstrApps] [‘derives’ QualId {‘,’ QualId}]

docs/docs/reference/contextual/extension-methods.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,30 +76,38 @@ extension [T: Numeric](x: T)
7676

7777
Type parameters on extensions can also be combined with type parameters on the methods
7878
themselves:
79+
7980
```scala
8081
extension [T](xs: List[T])
81-
def sumBy[U](f: T => U)(using Numeric[U]): U = ...
82+
def sumBy[U: Numeric](f: T => U): U = ...
8283
```
8384

8485
Type arguments matching method type parameters are passed as usual:
86+
8587
```scala
8688
List("a", "bb", "ccc").sumBy[Int](_.length)
8789
```
90+
8891
By contrast, type arguments matching type parameters following `extension` can be passed
8992
only if the method is referenced as a regular method:
93+
9094
```scala
9195
List[String]("a", "bb", "ccc").sumBy(_.length)
9296
```
97+
9398
or, passing, both type arguments
99+
94100
```scala
95101
List[String]("a", "bb", "ccc").sumBy[Int](_.length)
96102
```
103+
97104
Extensions can also take using clauses. For instance, the `+` extension above could equivalently be written with a using clause:
98105

99106
```scala
100107
extension [T](x: T)(using n: Numeric[T])
101108
def + (y: T): T = n.plus(x, y)
102109
```
110+
103111
### Collective Extensions
104112

105113
Sometimes, one wants to define several extension methods that share the same
@@ -214,7 +222,7 @@ class List[T]:
214222
object List:
215223
...
216224
extension [T](xs: List[List[T]])
217-
def flatten: List[T] = xs.foldLeft(Nil: List[T])(_ ++ _)
225+
def flatten: List[T] = xs.foldLeft(List.empty[T])(_ ++ _)
218226

219227
given [T: Ordering]: Ordering[List[T]] with
220228
extension (xs: List[T])
@@ -276,7 +284,7 @@ def position(s: String)(ch: Char, n: Int): Int =
276284
Here are the syntax changes for extension methods and collective extensions relative
277285
to the [current syntax](../syntax.md).
278286

279-
```
287+
```ebnf
280288
BlockStat ::= ... | Extension
281289
TemplateStat ::= ... | Extension
282290
TopStat ::= ... | Extension

docs/docs/reference/contextual/givens.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ object Foo:
134134
given fooTagged[A](using Tagged[A]): Foo[A] = Foo(true)
135135
given fooNotTagged[A](using NotGiven[Tagged[A]]): Foo[A] = Foo(false)
136136

137-
@main def test() =
137+
@main def test(): Unit =
138138
given Tagged[Int] with {}
139139
assert(summon[Foo[Int]].value) // fooTagged is found
140140
assert(!summon[Foo[String]].value) // fooNotTagged is found
@@ -150,7 +150,7 @@ is created for each reference.
150150

151151
Here is the syntax for given instances:
152152

153-
```
153+
```ebnf
154154
TmplDef ::= ...
155155
| ‘given’ GivenDef
156156
GivenDef ::= [GivenSig] StructuralInstance

docs/docs/reference/dropped-features/nonlocal-returns.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extension [T](xs: List[T])
1919
false
2020
}
2121

22-
@main def test =
22+
@main def test(): Unit =
2323
val xs = List(1, 2, 3, 4, 5)
2424
assert(xs.has(2) == xs.contains(2))
2525
```
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
---
22
layout: doc-page
3-
title: "Dropped: wildcard initializer"
3+
title: "Dropped: Wildcard Initializer"
44
---
55

66
The syntax
7+
78
```scala
89
var x: A = _
910
```
11+
1012
that was used to indicate an uninitialized field, has been dropped.
11-
At its place there is a special value `uninitialized` in the `scala.compiletime` package. To get an uninitialized field, you now write
13+
At its place there is a special value `uninitialized` in the `scala.compiletime` package.
14+
To get an uninitialized field, you now write
15+
1216
```scala
1317
import scala.compiletime.uninitialized
1418

1519
var x: A = uninitialized
1620
```
17-
To enable cross-compilation, `_` is still supported, but it will be dropped in a future 3.x version.
1821

22+
To enable cross-compilation, `_` is still supported, but it will be dropped in a future 3.x version.

docs/docs/reference/enums/adts.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ enum Option[+T]:
6565

6666
def isDefined: Boolean = this match
6767
case None => false
68-
case some => true
68+
case _ => true
6969

7070
object Option:
7171

@@ -153,7 +153,7 @@ The changes are specified below as deltas with respect to the Scala syntax given
153153

154154
1. Enum definitions are defined as follows:
155155

156-
```
156+
```ebnf
157157
TmplDef ::= `enum' EnumDef
158158
EnumDef ::= id ClassConstr [`extends' [ConstrApps]] EnumBody
159159
EnumBody ::= [nl] ‘{’ [SelfType] EnumStat {semi EnumStat} ‘}’
@@ -163,7 +163,7 @@ The changes are specified below as deltas with respect to the Scala syntax given
163163
164164
2. Cases of enums are defined as follows:
165165
166-
```
166+
```ebnf
167167
EnumCase ::= `case' (id ClassConstr [`extends' ConstrApps]] | ids)
168168
```
169169

docs/docs/reference/enums/desugarEnums.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ map into `case class`es or `val`s.
127127
starting from 0. The anonymous class also
128128
implements the abstract `Product` methods that it inherits from `Enum`.
129129

130-
131130
It is an error if a value case refers to a type parameter of the enclosing `enum`
132131
in a type argument of `<parents>`.
133132

@@ -198,6 +197,7 @@ Even though translated enum cases are located in the enum's companion object, re
198197
this object or its members via `this` or a simple identifier is also illegal. The compiler typechecks enum cases in the scope of the enclosing companion object but flags any such illegal accesses as errors.
199198

200199
### Translation of Java-compatible enums
200+
201201
A Java-compatible enum is an enum that extends `java.lang.Enum`. The translation rules are the same as above, with the reservations defined in this section.
202202

203203
It is a compile-time error for a Java-compatible enum to have class cases.
@@ -206,9 +206,9 @@ Cases such as `case C` expand to a `@static val` as opposed to a `val`. This all
206206

207207
### Other Rules
208208

209-
- A normal case class which is not produced from an enum case is not allowed to extend
210-
`scala.reflect.Enum`. This ensures that the only cases of an enum are the ones that are
211-
explicitly declared in it.
209+
- A normal case class which is not produced from an enum case is not allowed to extend
210+
`scala.reflect.Enum`. This ensures that the only cases of an enum are the ones that are
211+
explicitly declared in it.
212212

213-
- If an enum case has an `extends` clause, the enum class must be one of the
214-
classes that's extended.
213+
- If an enum case has an `extends` clause, the enum class must be one of the
214+
classes that's extended.

docs/docs/reference/enums/enums.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ end Planet
9393
As a library author, you may want to signal that an enum case is no longer intended for use. However you could still want to gracefully handle the removal of a case from your public API, such as special casing deprecated cases.
9494

9595
To illustrate, say that the `Planet` enum originally had an additional case:
96+
9697
```diff
9798
enum Planet(mass: Double, radius: Double):
9899
...
@@ -128,9 +129,11 @@ object Planet {
128129
}
129130
}
130131
```
132+
131133
We could imagine that a library may use [type class derivation](../contextual/derivation.md) to automatically provide an instance for `Deprecations`.
132134

133135
### Compatibility with Java Enums
136+
134137
If you want to use the Scala-defined enums as [Java enums](https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html), you can do so by extending
135138
the class `java.lang.Enum`, which is imported by default, as follows:
136139

docs/docs/reference/metaprogramming/inline.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ Inline methods can override other non-inline methods. The rules are as follows:
176176

177177
B.f // OK
178178
val a: A = B
179-
a.f // error: cannot inline f() in A.
179+
a.f // error: cannot inline f in A.
180180
```
181181

182182
### Relationship to `@inline`
@@ -285,11 +285,13 @@ val one: 1 = zero + 1
285285
```
286286

287287
### Transparent vs. non-transparent inline
288+
288289
As we already discussed, transparent inline methods may influence type checking at call site.
289290
Technically this implies that transparent inline methods must be expanded during type checking of the program.
290291
Other inline methods are inlined later after the program is fully typed.
291292

292293
For example, the following two functions will be typed the same way but will be inlined at different times.
294+
293295
```scala
294296
inline def f1: T = ...
295297
transparent inline def f2: T = (...): T
@@ -298,7 +300,7 @@ transparent inline def f2: T = (...): T
298300
A noteworthy difference is the behavior of `transparent inline given`.
299301
If there is an error reported when inlining that definition, it will be considered as an implicit search mismatch and the search will continue.
300302
A `transparent inline given` can add a type ascription in its RHS (as in `f2` from the previous example) to avoid the precise type but keep the search behavior.
301-
On the other hand, `inline given` be taken as the implicit and then inlined after typing.
303+
On the other hand, an `inline given` is taken as an implicit and then inlined after typing.
302304
Any error will be emitted as usual.
303305

304306
## Inline Conditionals

docs/docs/reference/metaprogramming/tasty-inspect.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ import scala.quoted.*
2222
import scala.tasty.inspector.*
2323

2424
class MyInspector extends Inspector:
25-
def inspect(using Quotes)(tastys: List[Tasty[quotes.type]]): Unit =
25+
def inspect(using Quotes)(tastys: List[Tasty[quotes.type]]): Unit =
2626
import quotes.reflect.*
2727
for tasty <- tastys do
28-
val tree = tasty.ast
29-
// Do something with the tree
28+
val tree = tasty.ast
29+
// Do something with the tree
3030
```
3131

3232
Then the consumer can be instantiated with the following code to get the tree of the `foo/Bar.tasty` file.
@@ -36,7 +36,6 @@ object Test:
3636
def main(args: Array[String]): Unit =
3737
val tastyFiles = List("foo/Bar.tasty")
3838
TastyInspector.inspectTastyFiles(tastyFiles)(new MyInspector)
39-
4039
```
4140

4241
Note that if we need to run the main (in the example below defined in an object called `Test`) after compilation we need to make the compiler available to the runtime:

0 commit comments

Comments
 (0)