Skip to content

Commit ce595b8

Browse files
committed
Apply procedure-syntax.md
1 parent 4392bc3 commit ce595b8

File tree

3 files changed

+17
-38
lines changed

3 files changed

+17
-38
lines changed

docs/_spec/04-basic-declarations-and-definitions.md

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -609,43 +609,6 @@ By contrast, the following application is well formed and yields again the resul
609609
sum(xs: _*)
610610
```
611611

612-
### Procedures
613-
614-
```ebnf
615-
FunDcl ::= FunSig
616-
FunDef ::= FunSig [nl] ‘{’ Block ‘}’
617-
```
618-
619-
Special syntax exists for procedures, i.e. methods that return the `Unit` value `()`.
620-
A _procedure declaration_ is a method declaration where the result type is omitted.
621-
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`.
622-
623-
A _procedure definition_ is a method definition where the result type and the equals sign are omitted; its defining expression must be a block.
624-
E.g., `def ´f´(´\mathit{ps}´) {´\mathit{stats}´}` is equivalent to `def ´f´(´\mathit{ps}´): Unit = {´\mathit{stats}´}`.
625-
626-
###### Example
627-
Here is a declaration and a definition of a procedure named `write`:
628-
629-
```scala
630-
trait Writer {
631-
def write(str: String)
632-
}
633-
object Terminal extends Writer {
634-
def write(str: String) { System.out.println(str) }
635-
}
636-
```
637-
638-
The code above is implicitly completed to the following code:
639-
640-
```scala
641-
trait Writer {
642-
def write(str: String): Unit
643-
}
644-
object Terminal extends Writer {
645-
def write(str: String): Unit = { System.out.println(str) }
646-
}
647-
```
648-
649612
### Method Return Type Inference
650613

651614
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.

docs/_spec/A?-scala-2-compatibility.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,20 @@ of `Int`.
1616

1717
When reading class files compiled with Scala 2, Scala 3 will do a best
1818
effort to approximate existential types with its own types. It will
19-
issue a warning that a precise emulation is not possible.
19+
issue a warning that a precise emulation is not possible.
20+
21+
### Procedure Syntax
22+
23+
Procedure syntax
24+
```scala
25+
def f() { ... }
26+
```
27+
has been dropped. You need to write one of the following instead:
28+
```scala
29+
def f() = { ... }
30+
def f(): Unit = { ... }
31+
```
32+
Scala 3 accepts the old syntax under the `-source:3.0-migration` option.
33+
If the `-migration` option is set, it can even rewrite old syntax to new.
34+
The [Scalafix](https://scalacenter.github.io/scalafix/) tool also
35+
can rewrite procedure syntax to make it Scala 3 compatible.

0 commit comments

Comments
 (0)