Skip to content

Commit a9029dc

Browse files
authored
Merge pull request #5399 from dotty-staging/fix-5163-bis
Tailrec improvements
2 parents ef84d2f + a129cbd commit a9029dc

23 files changed

+309
-300
lines changed

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

+1
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

+10-8
Original file line numberDiff line numberDiff line change
@@ -1801,14 +1801,16 @@ 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
1805-
val msg: String =
1806-
if (symbol.is(Method))
1807-
hl"TailRec optimisation not applicable, $symbol is neither ${"private"} nor ${"final"}."
1808-
else
1809-
hl"TailRec optimisation not applicable, ${symbolKind} isn't a method."
1810-
val explanation: String =
1811-
hl"A method annotated ${"@tailrec"} must be declared ${"private"} or ${"final"} so it can't be overridden."
1804+
val msg: String = {
1805+
val reason =
1806+
if (!symbol.is(Method)) hl"$symbol isn't a method"
1807+
else if (symbol.is(Deferred)) hl"$symbol is abstract"
1808+
else if (!symbol.isEffectivelyFinal) hl"$symbol is neither ${"private"} nor ${"final"} so can be overridden"
1809+
else hl"$symbol contains no recursive calls"
1810+
1811+
s"TailRec optimisation not applicable, $reason"
1812+
}
1813+
val explanation: String = ""
18121814
}
18131815

18141816
case class FailureToEliminateExistential(tp: Type, tp1: Type, tp2: Type, boundSyms: List[Symbol])(implicit ctx: Context)

0 commit comments

Comments
 (0)