Skip to content

Commit 0224192

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 ace9519 commit 0224192

38 files changed

+130
-215
lines changed

compiler/test/dotty/tools/dotc/FromTastyTests.scala

Lines changed: 19 additions & 105 deletions
Large diffs are not rendered by default.

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
342342
case _ =>
343343
this += "{"
344344
indented {
345-
if (!stats.isEmpty) {
346-
this += lineBreak()
347-
printTrees(stats, lineBreak())
348-
}
345+
printStats(stats)
349346
if (!isLoopEntryPoint(expr)) {
350347
this += lineBreak()
351348
printTree(expr)
@@ -355,12 +352,9 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
355352
}
356353

357354
case Term.Inlined(call, bindings, expansion) =>
358-
sb.append("{ // inlined")
355+
this += "{ // inlined"
359356
indented {
360-
if (!bindings.isEmpty) {
361-
this += lineBreak()
362-
printTrees(bindings, lineBreak())
363-
}
357+
printStats(bindings)
364358
this += lineBreak()
365359
printTree(expansion)
366360
}
@@ -414,6 +408,14 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
414408

415409
}
416410

411+
def printStats(stats: List[Tree]): Unit = {
412+
if (!stats.isEmpty) {
413+
this += lineBreak()
414+
printTrees(stats, ";" + lineBreak())
415+
this += ";"
416+
}
417+
}
418+
417419
def printTrees(trees: List[Tree], sep: String): Buffer = {
418420
def printSeparated(list: List[Tree]): Unit = list match {
419421
case Nil =>
@@ -602,14 +604,13 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
602604
}
603605
this += " =>"
604606
indented {
605-
this += lineBreak()
606607
body match {
607608
case Term.Block(stats, expr) =>
608-
printTrees(stats, lineBreak())
609-
if (stats.nonEmpty)
610-
this += lineBreak()
609+
printStats(stats)
610+
this += lineBreak()
611611
printTree(expr)
612612
case body =>
613+
this += lineBreak()
613614
printTree(body)
614615
}
615616
}

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 = Pair.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 = A.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 = A.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/pos/t704.decompiled

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ trait D() extends java.lang.Object {
1111
/** Decompiled from out/posTestFromTasty/pos/t704/E.class */
1212
trait E() extends java.lang.Object with D {
1313
def f(): scala.Unit = {
14-
val y: java.lang.String = "yyyy should appear twice"
14+
val y: java.lang.String = "yyyy should appear twice";
1515
object yyyy {
1616
val x1: scala.AnyRef = E.this.get_xxxx
1717
scala.Console.println(y)
18-
}
18+
};
1919
{
20-
yyyy
20+
yyyy;
2121
()
2222
}
2323
}
2424
}
2525
/** Decompiled from out/posTestFromTasty/pos/t704/Go.class */
2626
object Go extends D {
2727
def main(args: scala.Array[scala.Predef.String]): scala.Unit = {
28-
new C().f()
28+
new C().f();
2929
new C().f()
3030
}
3131
}

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,9 +1,9 @@
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] {
88
def apply(x: scala.Int): scala.Int
99
}).apply(x$1)

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
}

0 commit comments

Comments
 (0)