Skip to content

Change indentation to two spaces in docs #12407

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
May 11, 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
40 changes: 20 additions & 20 deletions docs/docs/reference/changed-features/compiler-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,28 @@ import dotty.tools.dotc.plugins.{PluginPhase, StandardPlugin}
import dotty.tools.dotc.transform.{Pickler, Staging}

class DivideZero extends StandardPlugin:
val name: String = "divideZero"
override val description: String = "divide zero check"
val name: String = "divideZero"
override val description: String = "divide zero check"

def init(options: List[String]): List[PluginPhase] =
(new DivideZeroPhase) :: Nil
def init(options: List[String]): List[PluginPhase] =
(new DivideZeroPhase) :: Nil

class DivideZeroPhase extends PluginPhase:
import tpd.*
import tpd.*

val phaseName = "divideZero"
val phaseName = "divideZero"

override val runsAfter = Set(Pickler.name)
override val runsBefore = Set(Staging.name)
override val runsAfter = Set(Pickler.name)
override val runsBefore = Set(Staging.name)

override def transformApply(tree: Apply)(implicit ctx: Context): Tree =
tree match
case Apply(Select(rcvr, nme.DIV), List(Literal(Constant(0))))
if rcvr.tpe <:< defn.IntType =>
report.error("dividing by zero", tree.pos)
case _ =>
()
tree
override def transformApply(tree: Apply)(implicit ctx: Context): Tree =
tree match
case Apply(Select(rcvr, nme.DIV), List(Literal(Constant(0))))
if rcvr.tpe <:< defn.IntType =>
report.error("dividing by zero", tree.pos)
case _ =>
()
tree
end DivideZeroPhase
```

Expand All @@ -109,11 +109,11 @@ import dotty.tools.dotc.core.Phases.Phase
import dotty.tools.dotc.plugins.ResearchPlugin

class DummyResearchPlugin extends ResearchPlugin:
val name: String = "dummy"
override val description: String = "dummy research plugin"
val name: String = "dummy"
override val description: String = "dummy research plugin"

def init(options: List[String], phases: List[List[Phase]])(implicit ctx: Context): List[List[Phase]] =
phases
def init(options: List[String], phases: List[List[Phase]])(implicit ctx: Context): List[List[Phase]] =
phases
end DummyResearchPlugin
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The standard library defines an abstract class `Conversion`:
package scala
@java.lang.FunctionalInterface
abstract class Conversion[-T, +U] extends Function1[T, U]:
def apply(x: T): U
def apply(x: T): U
```

Function literals are automatically converted to `Conversion` values.
Expand Down
10 changes: 5 additions & 5 deletions docs/docs/reference/changed-features/implicit-conversions.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ method that expects a `java.lang.Integer`
```scala
import scala.language.implicitConversions
implicit def int2Integer(x: Int): java.lang.Integer =
x.asInstanceOf[java.lang.Integer]
x.asInstanceOf[java.lang.Integer]
```

The second example shows how to use `Conversion` to define an
Expand All @@ -44,11 +44,11 @@ types:
```scala
import scala.language.implicitConversions
implicit def ordT[T, S](
implicit conv: Conversion[T, S],
ordS: Ordering[S]
implicit conv: Conversion[T, S],
ordS: Ordering[S]
): Ordering[T] =
// `ordS` compares values of type `S`, but we can convert from `T` to `S`
(x: T, y: T) => ordS.compare(x, y)
// `ordS` compares values of type `S`, but we can convert from `T` to `S`
(x: T, y: T) => ordS.compare(x, y)

class A(val x: Int) // The type for which we want an `Ordering`

Expand Down
20 changes: 10 additions & 10 deletions docs/docs/reference/changed-features/implicit-resolution.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ where the type may still be inferred:
```scala
class C {

val ctx: Context = ... // ok
val ctx: Context = ... // ok

/*!*/ implicit val x = ... // error: type must be given explicitly
/*!*/ implicit val x = ... // error: type must be given explicitly

/*!*/ implicit def y = ... // error: type must be given explicitly
/*!*/ implicit def y = ... // error: type must be given explicitly
}
val y = {
implicit val ctx = this.ctx // ok
...
implicit val ctx = this.ctx // ok
...
}
```
**2.** Nesting is now taken into account for selecting an implicit. Consider for instance the following scenario:
```scala
def f(implicit i: C) = {
def g(implicit j: C) = {
implicitly[C]
}
def g(implicit j: C) = {
implicitly[C]
}
}
```
This will now resolve the `implicitly` call to `j`, because `j` is nested
Expand All @@ -45,8 +45,8 @@ no longer applies.
given a: A = A()

object o:
given b: B = B()
type C
given b: B = B()
type C
```
Both `a` and `b` are visible as implicits at the point of the definition
of `type C`. However, a reference to `p.o.C` outside of package `p` will
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/reference/changed-features/imports.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ If you want to import a member named `*` specifically, you can use backticks aro

```scala
object A:
def * = ...
def min = ...
def * = ...
def min = ...

object B:
import A.`*` // imports just `*`
Expand Down
46 changes: 23 additions & 23 deletions docs/docs/reference/changed-features/main-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ Example:

```scala
@main def happyBirthday(age: Int, name: String, others: String*) =
val suffix =
age % 100 match
case 11 | 12 | 13 => "th"
case _ =>
age % 10 match
case 1 => "st"
case 2 => "nd"
case 3 => "rd"
case _ => "th"
val bldr = new StringBuilder(s"Happy $age$suffix birthday, $name")
for other <- others do bldr.append(" and ").append(other)
bldr.toString
val suffix =
age % 100 match
case 11 | 12 | 13 => "th"
case _ =>
age % 10 match
case 1 => "st"
case 2 => "nd"
case 3 => "rd"
case _ => "th"
val bldr = new StringBuilder(s"Happy $age$suffix birthday, $name")
for other <- others do bldr.append(" and ").append(other)
bldr.toString
```

This would generate a main program `happyBirthday` that could be called like this
Expand Down Expand Up @@ -62,15 +62,15 @@ For instance, the `happyBirthDay` method above would generate additional code eq

```scala
final class happyBirthday:
import scala.util.CommandLineParser as CLP
<static> def main(args: Array[String]): Unit =
try
happyBirthday(
CLP.parseArgument[Int](args, 0),
CLP.parseArgument[String](args, 1),
CLP.parseRemainingArguments[String](args, 2))
catch
case error: CLP.ParseError => CLP.showError(error)
import scala.util.CommandLineParser as CLP
<static> def main(args: Array[String]): Unit =
try
happyBirthday(
CLP.parseArgument[Int](args, 0),
CLP.parseArgument[String](args, 1),
CLP.parseRemainingArguments[String](args, 2))
catch
case error: CLP.ParseError => CLP.showError(error)
```

**Note**: The `<static>` modifier above expresses that the `main` method is generated
Expand All @@ -80,8 +80,8 @@ as a static method of class `happyBirthDay`. It is not available for user progra

```scala
object happyBirthday extends App:
// needs by-hand parsing of arguments vector
...
// needs by-hand parsing of arguments vector
...
```

The previous functionality of `App`, which relied on the "magic" [`DelayedInit`](../dropped-features/delayed-init.md) trait, is no longer available. [`App`](https://dotty.epfl.ch/api/scala/App.html) still exists in limited form for now, but it does not support command line arguments and will be deprecated in the future. If programs need to cross-build
Expand Down
20 changes: 10 additions & 10 deletions docs/docs/reference/changed-features/match-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@ The syntactical precedence of match expressions has been changed.

```scala
xs match {
case Nil => "empty"
case _ => "nonempty"
case Nil => "empty"
case _ => "nonempty"
} match {
case "empty" => 0
case "nonempty" => 1
case "empty" => 0
case "nonempty" => 1
}
```

(or, dropping the optional braces)

```scala
xs match
case Nil => "empty"
case _ => "nonempty"
case Nil => "empty"
case _ => "nonempty"
match
case "empty" => 0
case "nonempty" => 1
case "empty" => 0
case "nonempty" => 1
```

2. `match` may follow a period:

```scala
if xs.match
case Nil => false
case _ => true
case Nil => false
case _ => true
then "nonempty"
else "empty"
```
Expand Down
Loading