Skip to content

Commit 63421c4

Browse files
committed
Print ; at the end of statements to avoid ambiguity
For example, the first snippet is `foo.apply(...)` and the second is eval `foo` and then eval the block. ```scala foo { ... } ``` ```scala foo; { ... } ```
1 parent 1f523ea commit 63421c4

36 files changed

+121
-122
lines changed

library/src/scala/tasty/util/ShowSourceCode.scala

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
191191
case stats =>
192192
this += "{"
193193
indented {
194-
this += lineBreak()
195-
printTrees(stats, lineBreak())
194+
printStats(stats)
196195
}
197196
this += lineBreak() += "}"
198197
}
@@ -205,8 +204,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
205204
case stats =>
206205
this += "{"
207206
indented {
208-
this += lineBreak()
209-
printTrees(stats, lineBreak())
207+
printStats(stats)
210208
}
211209
this += lineBreak() += "}"
212210
}
@@ -328,10 +326,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
328326
case _ =>
329327
this += "{"
330328
indented {
331-
if (!stats.isEmpty) {
332-
this += lineBreak()
333-
printTrees(stats, lineBreak())
334-
}
329+
printStats(stats)
335330
if (!isLoopEntryPoint(expr)) {
336331
this += lineBreak()
337332
printTree(expr)
@@ -341,12 +336,9 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
341336
}
342337

343338
case Term.Inlined(call, bindings, expansion) =>
344-
sb.append("{ // inlined")
339+
this += "{ // inlined"
345340
indented {
346-
if (!bindings.isEmpty) {
347-
this += lineBreak()
348-
printTrees(bindings, lineBreak())
349-
}
341+
printStats(bindings)
350342
this += lineBreak()
351343
printTree(expansion)
352344
}
@@ -400,6 +392,14 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
400392

401393
}
402394

395+
def printStats(stats: List[Tree]): Unit = {
396+
if (!stats.isEmpty) {
397+
this += lineBreak()
398+
printTrees(stats, ";" + lineBreak())
399+
this += ";"
400+
}
401+
}
402+
403403
def printTrees(trees: List[Tree], sep: String): Buffer = {
404404
def printSeparated(list: List[Tree]): Unit = list match {
405405
case Nil =>
@@ -603,14 +603,13 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
603603
}
604604
this += " =>"
605605
indented {
606-
this += lineBreak()
607606
body match {
608607
case Term.Block(stats, expr) =>
609-
printTrees(stats, lineBreak())
610-
if (stats.nonEmpty)
611-
this += lineBreak()
608+
printStats(stats)
609+
this += lineBreak()
612610
printTree(expr)
613611
case body =>
612+
this += lineBreak()
614613
printTree(body)
615614
}
616615
}

tests/pos/i0306.decompiled

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ object bar {
44
val x: scala.AnyRef = new bar.C[scala.collection.Seq[_ >: scala.Nothing <: scala.Any]]()
55
val y: scala.collection.Seq[_ >: scala.Nothing <: scala.Any] = bar.x match {
66
case x: bar.C[u] =>
7-
def xx: u = xx
7+
def xx: u = xx;
88
((xx: u): scala.collection.Seq[_ >: scala.Nothing <: scala.Any])
99
}
1010
val z: java.lang.String = {
11-
def xx: scala.Predef.String = xx
11+
def xx: scala.Predef.String = xx;
1212
(xx: java.lang.String)
1313
}
1414
}

tests/pos/i2104b.decompiled

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ object Cons {
77
/** Decompiled from out/posTestFromTasty/pos/i2104b/Pair.class */
88
case class Pair[A, B](_1: A, _2: B) {
99
override def hashCode(): scala.Int = {
10-
var acc: scala.Int = 2479866
11-
acc = scala.runtime.Statics.mix(acc, scala.runtime.Statics.anyHash(Pair.this._1))
12-
acc = scala.runtime.Statics.mix(acc, scala.runtime.Statics.anyHash(Pair.this._2))
10+
var acc: scala.Int = 2479866;
11+
acc = scala.runtime.Statics.mix(acc, scala.runtime.Statics.anyHash(Pair.this._1));
12+
acc = scala.runtime.Statics.mix(acc, scala.runtime.Statics.anyHash(Pair.this._2));
1313
scala.runtime.Statics.finalizeHash(acc, 2)
1414
}
1515
override def equals(x$0: scala.Any): scala.Boolean = this.eq(x$0.asInstanceOf[java.lang.Object]).||(x$0 match {

tests/pos/simpleCaseClass-2.decompiled

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/** Decompiled from out/posTestFromTasty/pos/simpleCaseClass-2/A.class */
22
case class A(x: scala.Int) {
33
override def hashCode(): scala.Int = {
4-
var acc: scala.Int = 65
5-
acc = scala.runtime.Statics.mix(acc, A.this.x)
4+
var acc: scala.Int = 65;
5+
acc = scala.runtime.Statics.mix(acc, A.this.x);
66
scala.runtime.Statics.finalizeHash(acc, 1)
77
}
88
override def equals(x$0: scala.Any): scala.Boolean = this.eq(x$0.asInstanceOf[java.lang.Object]).||(x$0 match {

tests/pos/simpleCaseClass-3.decompiled

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/** Decompiled from out/posTestFromTasty/pos/simpleCaseClass-3/A.class */
22
case class A[T](x: T) {
33
override def hashCode(): scala.Int = {
4-
var acc: scala.Int = 65
5-
acc = scala.runtime.Statics.mix(acc, scala.runtime.Statics.anyHash(A.this.x))
4+
var acc: scala.Int = 65;
5+
acc = scala.runtime.Statics.mix(acc, scala.runtime.Statics.anyHash(A.this.x));
66
scala.runtime.Statics.finalizeHash(acc, 1)
77
}
88
override def equals(x$0: scala.Any): scala.Boolean = this.eq(x$0.asInstanceOf[java.lang.Object]).||(x$0 match {

tests/pos/simpleDoWhile.decompiled

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/** Decompiled from out/posTestFromTasty/pos/simpleDoWhile/Foo.class */
22
class Foo() {
33
def foo: scala.Unit = {
4-
var i: scala.Int = 1
4+
var i: scala.Int = 1;
55
do {
66
i = 0
77
} while (i.!=(0))
88
}
9-
}
9+
}

tests/pos/simpleMatchCase.decompiled

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class Foo() {
33
def foo: scala.Unit = {
44
"c" match {
55
case x =>
6-
scala.Predef.println("a")
6+
scala.Predef.println("a");
77
scala.Predef.println("b")
88
}
99
}

tests/pos/simpleSingleton.decompiled

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/** Decompiled from out/posTestFromTasty/pos/simpleSingleton/Foo.class */
22
class Foo() {
33
def foo(x: scala.Int): scala.Unit = {
4-
val a: x.type = x
5-
val b: Foo.type = Foo
6-
val c: Foo.Bar.type = Foo.Bar
7-
val d: 1 = 1
8-
val e: "abc" = "abc"
4+
val a: x.type = x;
5+
val b: Foo.type = Foo;
6+
val c: Foo.Bar.type = Foo.Bar;
7+
val d: 1 = 1;
8+
val e: "abc" = "abc";
99
()
1010
}
1111
}
1212
object Foo {
1313
object Bar
14-
}
14+
}

tests/pos/simpleWhile.decompiled

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/** Decompiled from out/posTestFromTasty/pos/simpleWhile/Foo.class */
22
class Foo() {
33
def foo: scala.Unit = {
4-
var i: scala.Int = 1
4+
var i: scala.Int = 1;
55
while (i.!=(0)) {
66
i = 0
77
}
88
}
9-
}
9+
}

tests/run-with-compiler/i3823-b.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
val z: scala.Int = 2
2+
val z: scala.Int = 2;
33
()
44
}

tests/run-with-compiler/i3823-c.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
val z: scala.Int = 2
2+
val z: scala.Int = 2;
33
()
44
}

tests/run-with-compiler/i3823.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
val z: scala.Int = 2
2+
val z: scala.Int = 2;
33
()
44
}

tests/run-with-compiler/i3876-b.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
6
22
{
3-
val x$1: scala.Int = 3
4-
def f(x: scala.Int): scala.Int = x.+(x)
3+
val x$1: scala.Int = 3;
4+
def f(x: scala.Int): scala.Int = x.+(x);
55
f(x$1)
66
}

tests/run-with-compiler/i3876-c.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
6
22
{
3-
val x$1: scala.Int = 3
3+
val x$1: scala.Int = 3;
44
val f: scala.Function1[scala.Int, scala.Int] {
55
def apply(x: scala.Int): scala.Int
6-
} = ((x: scala.Int) => x.+(x))
6+
} = ((x: scala.Int) => x.+(x));
77
(f: scala.Function1[scala.Int, scala.Int]).apply(x$1)
88
}

tests/run-with-compiler/i3876-d.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
6
22
{
3-
val x$1: scala.Int = 3
3+
val x$1: scala.Int = 3;
44
{ // inlined
55
x$1.+(x$1)
66
}

tests/run-with-compiler/i3876.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
6
22
{
3-
val x$1: scala.Int = 3
3+
val x$1: scala.Int = 3;
44
x$1.+(x$1)
55
}

tests/run-with-compiler/i4044b.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
var x: scala.Int = 4
3-
x = 3
2+
var x: scala.Int = 4;
3+
x = 3;
44
x
55
}

tests/run-with-compiler/i4044d.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
evaluating inner quote
22
{
3-
val b: scala.Int = 3
3+
val b: scala.Int = 3;
44
b.+(3)
55
}

tests/run-with-compiler/i4044f.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
val e1: scala.Int = 3
3-
val f1: scala.Int = 5
2+
val e1: scala.Int = 3;
3+
val f1: scala.Int = 5;
44
e1.+(2).+(f1)
55
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
val a: scala.quoted.Expr[scala.Int] = scala.quoted.Expr.apply[scala.Int](4)
2+
val a: scala.quoted.Expr[scala.Int] = scala.quoted.Expr.apply[scala.Int](4);
33
a
44
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
type T = scala.Predef.String
3-
val x: java.lang.String = "foo"
4-
val z: T = x
5-
()
2+
type T = scala.Predef.String;
3+
val x: java.lang.String = "foo";
4+
val z: T = x;
5+
();
66
(x: java.lang.String)
77
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
val t: scala.quoted.Type[scala.Predef.String] = scala.quoted.Type.apply[scala.Predef.String]
2+
val t: scala.quoted.Type[scala.Predef.String] = scala.quoted.Type.apply[scala.Predef.String];
33
(t: scala.quoted.Type[scala.Predef.String])
44
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
val a: scala.quoted.Expr[scala.Int] = scala.quoted.Expr.apply[scala.Int](4)
2+
val a: scala.quoted.Expr[scala.Int] = scala.quoted.Expr.apply[scala.Int](4);
33
a
44
}

tests/run-with-compiler/quote-owners-2.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
{
33
def ff: scala.Int = {
44
val a: immutable.List[scala.Int] = {
5-
type T = immutable.List[scala.Int]
6-
val b: T = scala.Nil.::[scala.Int](3)
5+
type T = immutable.List[scala.Int];
6+
val b: T = scala.Nil.::[scala.Int](3);
77
(b: collection.immutable.List[scala.Int])
8-
}
8+
};
99
(a.head: scala.Int)
10-
}
10+
};
1111
(ff: scala.Int)
1212
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
9
22
{
33
def ff: scala.Int = {
4-
val a: scala.Int = 9
4+
val a: scala.Int = 9;
55
a.+(0)
6-
}
6+
};
77
(ff: scala.Int)
88
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
1.0
22
5.0
33
{
4-
val y: scala.Double = 5.0.*(5.0)
4+
val y: scala.Double = 5.0.*(5.0);
55
y
66
}
77
5.0.*({
8-
val y: scala.Double = 5.0.*(5.0)
8+
val y: scala.Double = 5.0.*(5.0);
99
y
1010
})

tests/run-with-compiler/quote-run-staged-interpreter.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
9
88
---
99
{
10-
val y: scala.Int = 3
10+
val y: scala.Int = 3;
1111
2.+(y).+(4)
1212
}
1313
9

tests/run-with-compiler/quote-run-with-settings.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
val a: scala.Int = 3
3-
scala.Predef.println("foo")
2+
val a: scala.Int = 3;
3+
scala.Predef.println("foo");
44
2.+(a)
55
}
66
foo

tests/run-with-compiler/quote-run.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ foo
33
foo
44
5
55
{
6-
val a: scala.Int = 3
7-
scala.Predef.println("foo")
6+
val a: scala.Int = 3;
7+
scala.Predef.println("foo");
88
2.+(a)
99
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
scala.Predef.println(1)
2+
scala.Predef.println(1);
33
{
4-
scala.Predef.println(2)
4+
scala.Predef.println(2);
55
{
6-
scala.Predef.println(3)
6+
scala.Predef.println(3);
77
{
8-
scala.Predef.println(4)
8+
scala.Predef.println(4);
99
{
10-
scala.Predef.println(5)
10+
scala.Predef.println(5);
1111
()
1212
}
1313
}
@@ -19,14 +19,14 @@
1919
{
2020
{
2121
{
22-
()
22+
();
2323
scala.Predef.println(5)
24-
}
24+
};
2525
scala.Predef.println(4)
26-
}
26+
};
2727
scala.Predef.println(3)
28-
}
28+
};
2929
scala.Predef.println(2)
30-
}
30+
};
3131
scala.Predef.println(1)
3232
}

0 commit comments

Comments
 (0)