Skip to content

Commit 310769a

Browse files
committed
Fix snippets in scala.compiletime
1 parent a86c97a commit 310769a

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

library/src/scala/compiletime/ops/int.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object int:
99
* case 0 => 1
1010
* case 1 => 2
1111
* case 2 => 3
12-
* ...
12+
* // ...
1313
* case 2147483646 => 2147483647
1414
* }
1515
* ```
@@ -152,8 +152,8 @@ object int:
152152

153153
/** Negation of an `Int` singleton type.
154154
* ```scala
155-
* val neg1: Neg[-1] = 1
156-
* val neg2: Neg[1] = -1
155+
* val neg1: Negate[-1] = 1
156+
* val neg2: Negate[1] = -1
157157
* ```
158158
* @syntax markdown
159159
*/

library/src/scala/compiletime/package.scala

+28-7
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@ import annotation.compileTimeOnly
77
* pattern match on it. For example, given a type `Tup <: Tuple`, one can
88
* pattern-match on it as follows:
99
* ```scala
10+
* //{
11+
* type Tup
12+
* inline def f = {
13+
* //}
1014
* inline erasedValue[Tup] match {
11-
* case _: EmptyTuple => ...
12-
* case _: h *: t => ...
15+
* case _: EmptyTuple => ???
16+
* case _: (h *: t) => ???
1317
* }
18+
* //{
19+
* }
20+
* //}
1421
* ```
1522
* This value can only be used in an inline match and the value cannot be used in
1623
* the branches.
@@ -21,7 +28,12 @@ def erasedValue[T]: T = ???
2128

2229
/** Used as the initializer of a mutable class or object field, like this:
2330
*
24-
* var x: T = uninitialized
31+
* ```scala
32+
* //{
33+
* type T
34+
* //}
35+
* var x: T = uninitialized
36+
* ```
2537
*
2638
* This signifies that the field is not initialized on its own. It is still initialized
2739
* as part of the bulk initialization of the object it belongs to, which assigns zero
@@ -33,7 +45,7 @@ def uninitialized: Nothing = ???
3345
/** The error method is used to produce user-defined compile errors during inline expansion.
3446
* If an inline expansion results in a call error(msgStr) the compiler produces an error message containing the given msgStr.
3547
*
36-
* ```scala
48+
* ```scala sc:fail
3749
* error("My error message")
3850
* ```
3951
* or
@@ -71,13 +83,13 @@ transparent inline def codeOf(arg: Any): String =
7183
* inlining and constant folding.
7284
*
7385
* Usage:
74-
* ```scala
86+
* ```scala sc:fail
7587
* inline def twice(inline n: Int): Int =
7688
* requireConst(n) // compile-time assertion that the parameter `n` is a constant
7789
* n + n
7890
*
7991
* twice(1)
80-
* val m: Int = ...
92+
* val m: Int = ???
8193
* twice(m) // error: expected a constant value but found: m
8294
* ```
8395
* @syntax markdown
@@ -116,14 +128,23 @@ end constValueTuple
116128
/** Summons first given matching one of the listed cases. E.g. in
117129
*
118130
* ```scala
119-
* given B { ... }
131+
* //{
132+
* type A
133+
* trait B
134+
* type C
135+
* inline def f = {
136+
* //}
137+
* given B with { }
120138
*
121139
* summonFrom {
122140
* case given A => 1
123141
* case given B => 2
124142
* case given C => 3
125143
* case _ => 4
126144
* }
145+
* //{
146+
* }
147+
* //}
127148
* ```
128149
* the returned value would be `2`.
129150
* @syntax markdown

project/Build.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ object Build {
14181418
"-versions-dictionary-url",
14191419
"https://scala-lang.org/api/versions.json",
14201420
"-Ydocument-synthetic-types",
1421-
s"-snippet-compiler:${dottyLibRoot}/scala/quoted=compile"
1421+
s"-snippet-compiler:${dottyLibRoot}/scala/quoted=compile,${dottyLibRoot}/scala/compiletime=compile"
14221422
) ++ (if (justAPI) Nil else Seq("-siteroot", "docs", "-Yapi-subdirectory")))
14231423

14241424
if (dottyJars.isEmpty) Def.task { streams.value.log.error("Dotty lib wasn't found") }

0 commit comments

Comments
 (0)