Skip to content

Commit 8f434b9

Browse files
committed
implement requested changes
1 parent bc6ac51 commit 8f434b9

File tree

4 files changed

+10
-13
lines changed

4 files changed

+10
-13
lines changed

compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public enum ErrorMessageID {
102102
UncheckedTypePatternID,
103103
ExtendFinalClassID,
104104
EnumCaseDefinitionInNonEnumOwnerID,
105-
TailrecNotApplicableNeitherPrivateNorFinalID,
105+
TailrecNotApplicableID,
106106
;
107107

108108
public int errorNumber() {

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,13 +1789,11 @@ object messages {
17891789
}
17901790

17911791

1792-
case class TailrecNotApplicableNeitherPrivateNorFinal(owner: Symbol)(implicit ctx: Context)
1793-
extends Message(TailrecNotApplicableNeitherPrivateNorFinalID) {
1792+
case class TailrecNotApplicable(method: Symbol)(implicit ctx: Context)
1793+
extends Message(TailrecNotApplicableID) {
17941794
val kind = "Syntax"
1795-
val msg = hl"TailRec optimisation not applicable, ${owner} is neither `private` nor `final` so can be overridden"
1795+
val msg = hl"TailRec optimisation not applicable, $method is neither ${"private"} nor ${"final"}."
17961796
val explanation =
1797-
hl"""
1798-
|The `@tailrec` annotation can only be used on methods that are either `private` or `final`.
1799-
"""
1797+
hl"A method annotated ${"@tailrec"} must be declared ${"private"} or ${"final"} so it can't be overridden."
18001798
}
18011799
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Symbols._
1212
import Types._
1313
import NameKinds.TailLabelName
1414
import TreeTransforms.{MiniPhaseTransform, TransformerInfo}
15-
import reporting.diagnostic.messages.TailrecNotApplicableNeitherPrivateNorFinal
15+
import reporting.diagnostic.messages.TailrecNotApplicable
1616

1717
/**
1818
* A Tail Rec Transformer
@@ -163,7 +163,7 @@ class TailRec extends MiniPhaseTransform with DenotTransformer with FullParamete
163163
})
164164
}
165165
case d: DefDef if d.symbol.hasAnnotation(defn.TailrecAnnot) || methodsWithInnerAnnots.contains(d.symbol) =>
166-
ctx.error(TailrecNotApplicableNeitherPrivateNorFinal(sym), sym.pos)
166+
ctx.error(TailrecNotApplicable(sym), sym.pos)
167167
d
168168
case d if d.symbol.hasAnnotation(defn.TailrecAnnot) || methodsWithInnerAnnots.contains(d.symbol) =>
169169
ctx.error("TailRec optimisation not applicable, not a method", sym.pos)

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,21 +1023,20 @@ class ErrorMessagesTests extends ErrorMessagesTest {
10231023
assertMessageCount(1, messages)
10241024
val EnumCaseDefinitionInNonEnumOwner(owner) :: Nil = messages
10251025
assertEquals("object Qux", owner.show)
1026+
}
10261027

10271028
@Test def tailrecNotApplicableNeitherPrivateNorFinal =
10281029
checkMessagesAfter("tailrec") {
10291030
"""
10301031
|class Foo {
1031-
|
10321032
| @scala.annotation.tailrec
10331033
| def foo: Unit = foo
1034-
|
10351034
|}
10361035
""".stripMargin
10371036
}.expect { (ictx, messages) =>
10381037
implicit val ctx: Context = ictx
10391038
assertMessageCount(1, messages)
1040-
val TailrecNotApplicableNeitherPrivateNorFinal(symbol) :: Nil = messages
1041-
assertEquals(symbol.show, "method foo")
1039+
val TailrecNotApplicable(method) :: Nil = messages
1040+
assertEquals(method.show, "method foo")
10421041
}
10431042
}

0 commit comments

Comments
 (0)