Skip to content

Fix markdown syntax for scala3 library docstrings #11612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions library/src/scala/Tuple.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,14 @@ object Tuple {

/** Filters out those members of the tuple for which the predicate `P` returns `false`.
* A predicate `P[X]` is a type that can be either `true` or `false`. For example:
* ```
* ```scala
* type IsString[x] = x match {
* case String => true
* case _ => false
* }
* Filter[(1, "foo", 2, "bar"), IsString] =:= ("foo", "bar")
* ```
* ```
* @syntax markdown
*/
type Filter[Tup <: Tuple, P[_] <: Boolean] <: Tuple = Tup match {
case EmptyTuple => EmptyTuple
Expand Down
2 changes: 2 additions & 0 deletions library/src/scala/compiletime/ops/any.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ object any:
* val eq2: 1 == "1" = false
* val eq3: "1" == "1" = true
* ```
* @syntax markdown
*/
type ==[X, Y] <: Boolean

Expand All @@ -17,5 +18,6 @@ object any:
* val eq2: 1 != "1" = true
* val eq3: "1" != "1" = false
* ```
* @syntax markdown
*/
type !=[X, Y] <: Boolean
20 changes: 12 additions & 8 deletions library/src/scala/compiletime/ops/boolean.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ object boolean:
* val notFalse: ![false] = true
* val notTrue: ![true] = false
* ```
* @syntax markdown
*/
type ![X <: Boolean] <: Boolean

/** Exclusive disjunction of two `Boolean` singleton types.
* ```scala
* val a: true ^ true = false
* val b: false ^ true = true
* ```
* ```scala
* val a: true ^ true = false
* val b: false ^ true = true
* ```
* @syntax markdown
*/
type ^[X <: Boolean, Y <: Boolean] <: Boolean

Expand All @@ -24,13 +26,15 @@ object boolean:
* val a: true && true = true
* val b: false && true = false
* ```
* @syntax markdown
*/
type &&[X <: Boolean, Y <: Boolean] <: Boolean

/** Disjunction of two `Boolean` singleton types.
* ```scala
* val a: true || false = true
* val b: false || false = false
* ```
* ```scala
* val a: true || false = true
* val b: false || false = false
* ```
* @syntax markdown
*/
type ||[X <: Boolean, Y <: Boolean] <: Boolean
20 changes: 20 additions & 0 deletions library/src/scala/compiletime/ops/int.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,62 +6,71 @@ object int:
* ```scala
* val sum: 2 + 2 = 4
* ```
* @syntax markdown
*/
type +[X <: Int, Y <: Int] <: Int

/** Subtraction of two `Int` singleton types.
* ```scala
* val sub: 4 - 2 = 2
* ```
* @syntax markdown
*/
type -[X <: Int, Y <: Int] <: Int

/** Multiplication of two `Int` singleton types.
* ```scala
* val mul: 4 * 2 = 8
* ```
* @syntax markdown
*/
type *[X <: Int, Y <: Int] <: Int

/** Integer division of two `Int` singleton types.
* ```scala
* val div: 5 / 2 = 2
* ```
* @syntax markdown
*/
type /[X <: Int, Y <: Int] <: Int

/** Remainder of the division of `X` by `Y`.
* ```scala
* val mod: 5 % 2 = 1
* ```
* @syntax markdown
*/
type %[X <: Int, Y <: Int] <: Int

/** Binary left shift of `X` by `Y`.
* ```scala
* val lshift: 1 << 2 = 4
* ```
* @syntax markdown
*/
type <<[X <: Int, Y <: Int] <: Int

/** Binary right shift of `X` by `Y`.
* ```scala
* val rshift: 10 >> 1 = 5
* ```
* @syntax markdown
*/
type >>[X <: Int, Y <: Int] <: Int

/** Binary right shift of `X` by `Y`, filling the left with zeros.
* ```scala
* val rshiftzero: 10 >>> 1 = 5
* ```
* @syntax markdown
*/
type >>>[X <: Int, Y <: Int] <: Int

/** Bitwise xor of `X` and `Y`.
* ```scala
* val xor: 10 ^ 30 = 20
* ```
* @syntax markdown
*/
type ^[X <: Int, Y <: Int] <: Int

Expand All @@ -70,6 +79,7 @@ object int:
* val lt1: 4 < 2 = false
* val lt2: 2 < 4 = true
* ```
* @syntax markdown
*/
type <[X <: Int, Y <: Int] <: Boolean

Expand All @@ -78,6 +88,7 @@ object int:
* val gt1: 4 > 2 = true
* val gt2: 2 > 2 = false
* ```
* @syntax markdown
*/
type >[X <: Int, Y <: Int] <: Boolean

Expand All @@ -86,6 +97,7 @@ object int:
* val ge1: 4 >= 2 = true
* val ge2: 2 >= 3 = false
* ```
* @syntax markdown
*/
type >=[X <: Int, Y <: Int] <: Boolean

Expand All @@ -94,6 +106,7 @@ object int:
* val lt1: 4 <= 2 = false
* val lt2: 2 <= 2 = true
* ```
* @syntax markdown
*/
type <=[X <: Int, Y <: Int] <: Boolean

Expand All @@ -102,20 +115,23 @@ object int:
* val and1: BitwiseAnd[4, 4] = 4
* val and2: BitwiseAnd[10, 5] = 0
* ```
* @syntax markdown
*/
type BitwiseAnd[X <: Int, Y <: Int] <: Int

/** Bitwise or of `X` and `Y`.
* ```scala
* val or: BitwiseOr[10, 11] = 11
* ```
* @syntax markdown
*/
type BitwiseOr[X <: Int, Y <: Int] <: Int

/** Absolute value of an `Int` singleton type.
* ```scala
* val abs: Abs[-1] = 1
* ```
* @syntax markdown
*/
type Abs[X <: Int] <: Int

Expand All @@ -124,26 +140,30 @@ object int:
* val neg1: Neg[-1] = 1
* val neg2: Neg[1] = -1
* ```
* @syntax markdown
*/
type Negate[X <: Int] <: Int

/** Minimum of two `Int` singleton types.
* ```scala
* val min: Min[-1, 1] = -1
* ```
* @syntax markdown
*/
type Min[X <: Int, Y <: Int] <: Int

/** Maximum of two `Int` singleton types.
* ```scala
* val max: Max[-1, 1] = 1
* ```
* @syntax markdown
*/
type Max[X <: Int, Y <: Int] <: Int

/** String conversion of an `Int` singleton type.
* ```scala
* val abs: ToString[1] = "1"
* ```
* @syntax markdown
*/
type ToString[X <: Int] <: String
1 change: 1 addition & 0 deletions library/src/scala/compiletime/ops/string.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ object string:
* ```scala
* val hello: "hello " + "world" = "hello world"
* ```
* @syntax markdown
*/
type +[X <: String, Y <: String] <: String
49 changes: 30 additions & 19 deletions library/src/scala/compiletime/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ package object compiletime {
/** Use this method when you have a type, do not have a value for it but want to
* pattern match on it. For example, given a type `Tup <: Tuple`, one can
* pattern-match on it as follows:
* ```
* ```scala
* inline erasedValue[Tup] match {
* case _: EmptyTuple => ...
* case _: h *: t => ...
* }
* ```
* This value can only be used in an inline match and the value cannot be used in
* the branches.
* @syntax markdown
*/
erased def erasedValue[T]: T = ???

Expand All @@ -39,6 +40,7 @@ package object compiletime {
* inline def errorOnThisCode(inline x: Any) =
* error("My error of this code: " + codeOf(x))
* ```
* @syntax markdown
*/
inline def error(inline msg: String): Nothing = ???

Expand All @@ -55,8 +57,10 @@ package object compiletime {
*
* The formatting of the code is not stable across version of the compiler.
*
* @note only `inline` arguments will be displayed as "code".
* Other values may display unintutively.
* @note only `inline` arguments will be displayed as "code".
* Other values may display unintutively.
*
* @syntax markdown
*/
transparent inline def codeOf(arg: Any): String =
// implemented in dotty.tools.dotc.typer.Inliner.Intrinsics
Expand All @@ -75,6 +79,7 @@ package object compiletime {
* val m: Int = ...
* twice(m) // error: expected a constant value but found: m
* ```
* @syntax markdown
*/
inline def requireConst(inline x: Boolean | Byte | Short | Int | Long | Float | Double | Char | String): Unit =
// implemented in dotty.tools.dotc.typer.Inliner
Expand All @@ -97,10 +102,11 @@ package object compiletime {

/**
* Use this type to widen a self-type to a tuple. E.g.
* ```
* ```scala
* val x: (1, 3) = (1, 3)
* val y: Widen[x.type] = x
* ```
* @syntax markdown
*/
type Widen[Tup <: Tuple] <: Tuple = Tup match {
case EmptyTuple => EmptyTuple
Expand All @@ -121,16 +127,18 @@ package object compiletime {

/** Summons first given matching one of the listed cases. E.g. in
*
* given B { ... }
*
* summonFrom {
* case given A => 1
* case given B => 2
* case given C => 3
* case _ => 4
* }
* ```scala
* given B { ... }
*
* summonFrom {
* case given A => 1
* case given B => 2
* case given C => 3
* case _ => 4
* }
* ```
* the returned value would be `2`.
* @syntax markdown
*/
transparent inline def summonFrom[T](f: Nothing => T): T =
error("Compiler bug: `summonFrom` was not evaluated by the compiler")
Expand Down Expand Up @@ -162,13 +170,16 @@ package object compiletime {

/** Succesor of a natural number where zero is the type 0 and successors are reduced as if the definition was
*
* type S[N <: Int] <: Int = N match {
* case 0 => 1
* case 1 => 2
* case 2 => 3
* ...
* case 2147483646 => 2147483647
* }
* ```scala
* type S[N <: Int] <: Int = N match {
* case 0 => 1
* case 1 => 2
* case 2 => 3
* ...
* case 2147483646 => 2147483647
* }
* ```
* @syntax markdown
*/
type S[N <: Int] <: Int

Expand Down
4 changes: 2 additions & 2 deletions library/src/scala/quoted/Expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ object Expr {
* Otherwise returns `None`.
*
* Usage:
* ```
* ```scala
* case '{ ... ${expr @ Expr(value)}: T ...} =>
* // expr: Expr[T]
* // value: T
* ```
*
* To directly get the value of an expression `expr: Expr[T]` consider using `expr.value`/`expr.valueOrError` insead.
* @syntax markdown
*/
def unapply[T](x: Expr[T])(using FromExpr[T])(using Quotes): Option[T] =
scala.Predef.summon[FromExpr[T]].unapply(x)
Expand All @@ -57,7 +58,6 @@ object Expr {
* `Seq(e1, e2, ...)` where `ei: Expr[T]`
* to an expression equivalent to
* `'{ Seq($e1, $e2, ...) }` typed as an `Expr[Seq[T]]`
* ```
*/
def ofSeq[T](xs: Seq[Expr[T]])(using Type[T])(using Quotes): Expr[Seq[T]] =
Varargs(xs)
Expand Down
Loading