Skip to content

Commit

Permalink
Apply procedure-syntax.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin Bernet authored and sjrd committed Apr 28, 2023
1 parent d88f3b8 commit 04ceaef
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 38 deletions.
37 changes: 0 additions & 37 deletions docs/_spec/04-basic-declarations-and-definitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -609,43 +609,6 @@ By contrast, the following application is well formed and yields again the resul
sum(xs: _*)
```

### Procedures

```ebnf
FunDcl ::= FunSig
FunDef ::= FunSig [nl] ‘{’ Block ‘}’
```

Special syntax exists for procedures, i.e. methods that return the `Unit` value `()`.
A _procedure declaration_ is a method declaration where the result type is omitted.
The result type is then implicitly completed to the `Unit` type. E.g., `def ´f´(´\mathit{ps}´)` is equivalent to `def ´f´(´\mathit{ps}´): Unit`.

A _procedure definition_ is a method definition where the result type and the equals sign are omitted; its defining expression must be a block.
E.g., `def ´f´(´\mathit{ps}´) {´\mathit{stats}´}` is equivalent to `def ´f´(´\mathit{ps}´): Unit = {´\mathit{stats}´}`.

###### Example
Here is a declaration and a definition of a procedure named `write`:

```scala
trait Writer {
def write(str: String)
}
object Terminal extends Writer {
def write(str: String) { System.out.println(str) }
}
```

The code above is implicitly completed to the following code:

```scala
trait Writer {
def write(str: String): Unit
}
object Terminal extends Writer {
def write(str: String): Unit = { System.out.println(str) }
}
```

### Method Return Type Inference

A class member definition ´m´ that overrides some other method ´m'´ in a base class of ´C´ may leave out the return type, even if it is recursive.
Expand Down
18 changes: 17 additions & 1 deletion docs/_spec/A2-scala-2-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,20 @@ of `Int`.

When reading class files compiled with Scala 2, Scala 3 will do a best
effort to approximate existential types with its own types. It will
issue a warning that a precise emulation is not possible.
issue a warning that a precise emulation is not possible.

### Procedure Syntax

Procedure syntax
```scala
def f() { ... }
```
has been dropped. You need to write one of the following instead:
```scala
def f() = { ... }
def f(): Unit = { ... }
```
Scala 3 accepts the old syntax under the `-source:3.0-migration` option.
If the `-migration` option is set, it can even rewrite old syntax to new.
The [Scalafix](https://scalacenter.github.io/scalafix/) tool also
can rewrite procedure syntax to make it Scala 3 compatible.

0 comments on commit 04ceaef

Please sign in to comment.