Skip to content

Commit fa28ab1

Browse files
committed
Cleanup Tailrec
1 parent 4385494 commit fa28ab1

File tree

19 files changed

+224
-277
lines changed

19 files changed

+224
-277
lines changed

compiler/src/dotty/tools/dotc/config/Printers.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ object Printers {
3232
val plugins: Printer = noPrinter
3333
val simplify: Printer = noPrinter
3434
val subtyping: Printer = noPrinter
35+
val tailrec: Printer = noPrinter
3536
val transforms: Printer = noPrinter
3637
val typr: Printer = noPrinter
3738
val unapp: Printer = noPrinter

compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,12 +1801,11 @@ object messages {
18011801
case class TailrecNotApplicable(symbol: Symbol)(implicit ctx: Context)
18021802
extends Message(TailrecNotApplicableID) {
18031803
val kind: String = "Syntax"
1804-
val symbolKind: String = symbol.showKind
18051804
val msg: String =
18061805
if (symbol.is(Method))
1807-
hl"TailRec optimisation not applicable, $symbol is neither ${"private"} nor ${"final"}."
1806+
"TailRec optimisation not applicable, method not tail recursive"
18081807
else
1809-
hl"TailRec optimisation not applicable, ${symbolKind} isn't a method."
1808+
hl"TailRec optimisation not applicable, ${symbol.showKind} isn't a method."
18101809
val explanation: String =
18111810
hl"A method annotated ${"@tailrec"} must be declared ${"private"} or ${"final"} so it can't be overridden."
18121811
}

compiler/src/dotty/tools/dotc/transform/TailRec.scala

Lines changed: 156 additions & 179 deletions
Large diffs are not rendered by default.

compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,8 +1507,8 @@ class ErrorMessagesTests extends ErrorMessagesTest {
15071507
implicit val ctx: Context = ictx
15081508
assertMessageCount(4, messages)
15091509

1510-
val tailRegMessages = messages.map({ case m: TailrecNotApplicable => m.symbolKind }).toSet
1511-
assertEquals(tailRegMessages, Set("variable", "value", "object", "class"))
1510+
val tailRecMessages = messages.map({ case TailrecNotApplicable(sym) => sym.showKind }).toSet
1511+
assertEquals(tailRecMessages, Set("variable", "value", "object", "class"))
15121512
}
15131513

15141514
@Test def notAnExtractor() =

tests/neg-tailcall/t1672b.check

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/neg-tailcall/t1672b.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import annotation.tailrec
2+
13
object Test1772B {
2-
@annotation.tailrec
4+
@tailrec
35
def bar : Nothing = { // error: TailRec optimisation not applicable
46
try {
57
throw new RuntimeException
@@ -10,7 +12,7 @@ object Test1772B {
1012
}
1113
}
1214

13-
@annotation.tailrec
15+
@tailrec
1416
def baz : Nothing = { // error: TailRec optimisation not applicable
1517
try {
1618
throw new RuntimeException
@@ -21,7 +23,7 @@ object Test1772B {
2123
}
2224
}
2325

24-
@annotation.tailrec
26+
@tailrec
2527
def boz : Nothing = { // error: TailRec optimisation not applicable
2628
try {
2729
throw new RuntimeException
@@ -30,7 +32,7 @@ object Test1772B {
3032
}
3133
}
3234

33-
@annotation.tailrec
35+
@tailrec
3436
def bez : Nothing = { // error: TailRec optimisation not applicable
3537
try {
3638
bez // error: it is not in tail position
@@ -40,7 +42,7 @@ object Test1772B {
4042
}
4143

4244
// the `liftedTree` local method will prevent a tail call here.
43-
@annotation.tailrec
45+
@tailrec
4446
def bar(i : Int) : Int = { // error: TailRec optimisation not applicable
4547
if (i == 0) 0
4648
else 1 + (try {

tests/neg-tailcall/t3275.check

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/neg-tailcall/t3275.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
object Test {
2-
@annotation.tailrec def foo() = 5 // error
2+
@annotation.tailrec def foo() = 5 // error: not recursive
33
}

tests/neg-tailcall/t6574.check

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/neg-tailcall/t6574.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import annotation.tailrec
2+
13
class Bad[X, Y](val v: Int) extends AnyVal {
2-
@annotation.tailrec final def notTailPos[Z](a: Int)(b: String): Unit = { // error
3-
this.notTailPos[Z](a)(b) // error
4+
@tailrec final def notTailPos[Z](a: Int)(b: String): Unit = { // error: TailRec optimisation not applicable
5+
this.notTailPos[Z](a)(b) // error: it is not in tail position
46
println("tail")
57
}
68

7-
@annotation.tailrec final def differentTypeArgs: Unit = {
9+
@tailrec final def differentTypeArgs: Unit = {
810
{(); new Bad[String, Unit](0)}.differentTypeArgs
911
}
1012
}

0 commit comments

Comments
 (0)