Commit ede1261
authored
Pretty-print lambdas (#21846)
Before:
```scala
[[syntax trees at end of typer]] // tests/printing/lambdas.scala
package <empty> {
final lazy module val Main: Main = new Main()
final module class Main() extends Object() { this: Main.type =>
val f1: Int => Int =
{
def $anonfun(x: Int): Int = x.+(1)
closure($anonfun)
}
val f2: (Int, Int) => Int =
{
def $anonfun(x: Int, y: Int): Int = x.+(y)
closure($anonfun)
}
val f3: Int => Int => Int =
{
def $anonfun(x: Int): Int => Int =
{
def $anonfun(y: Int): Int = x.+(y)
closure($anonfun)
}
closure($anonfun)
}
val f4: [T] => (x: Int) => Int =
{
def $anonfun[T >: Nothing <: Any](x: Int): Int = x.+(1)
closure($anonfun)
}
val f5: [T] => (x: Int) => Int => Int =
{
def $anonfun[T >: Nothing <: Any](x: Int): Int => Int =
{
def $anonfun(y: Int): Int = x.+(y)
closure($anonfun)
}
closure($anonfun)
}
val f6: Int => Int =
{
def $anonfun(x: Int): Int =
{
val x2: Int = x.+(1)
x2.+(1)
}
closure($anonfun)
}
def f7(x: Int): Int = x.+(1)
val f8: Int => Int =
{
def $anonfun(x: Int): Int = Main.f7(x)
closure($anonfun)
}
val l: List[Int] = List.apply[Int]([1,2,3 : Int]*)
Main.l.map[Int](
{
def $anonfun(_$1: Int): Int = _$1.+(1)
closure($anonfun)
}
)
Main.l.map[Int](
{
def $anonfun(x: Int): Int = x.+(1)
closure($anonfun)
}
)
Main.l.map[Int](
{
def $anonfun(x: Int): Int =
{
val x2: Int = x.+(1)
x2.+(1)
}
closure($anonfun)
}
)
Main.l.map[Int](
{
def $anonfun(x: Int): Int = Main.f7(x)
closure($anonfun)
}
)
}
}
```
After:
```scala
[[syntax trees at end of typer]] // tests/printing/lambdas.scala
package <empty> {
final lazy module val Main: Main = new Main()
final module class Main() extends Object() { this: Main.type =>
val f1: Int => Int = (x: Int) => x.+(1)
val f2: (Int, Int) => Int = (x: Int, y: Int) => x.+(y)
val f3: Int => Int => Int = (x: Int) => (y: Int) => x.+(y)
val f4: [T] => (x: Int) => Int = [T >: Nothing <: Any] => (x: Int) => x.+(1)
val f5: [T] => (x: Int) => Int => Int = [T >: Nothing <: Any] => (x: Int)
=> (y: Int) => x.+(y)
val f6: Int => Int = (x: Int) =>
{
val x2: Int = x.+(1)
x2.+(1)
}
def f7(x: Int): Int = x.+(1)
val f8: Int => Int = (x: Int) => Main.f7(x)
val l: List[Int] = List.apply[Int]([1,2,3 : Int]*)
Main.l.map[Int]((_$1: Int) => _$1.+(1))
Main.l.map[Int]((x: Int) => x.+(1))
Main.l.map[Int]((x: Int) =>
{
val x2: Int = x.+(1)
x2.+(1)
}
)
Main.l.map[Int]((x: Int) => Main.f7(x))
}
}
```
The ugly thing can still be displayed with `-Yprint-debug`.File tree
4 files changed
+50
-16
lines changed- compiler/src/dotty/tools/dotc/printing
- tests/printing
4 files changed
+50
-16
lines changedLines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
510 | 511 | | |
511 | 512 | | |
512 | 513 | | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
513 | 517 | | |
514 | 518 | | |
515 | 519 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
| 10 | + | |
18 | 11 | | |
19 | 12 | | |
20 | 13 | | |
21 | 14 | | |
22 | 15 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
| 16 | + | |
31 | 17 | | |
32 | 18 | | |
33 | 19 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
0 commit comments