Skip to content

Commit 9fb8148

Browse files
committed
add and use error message and id
1 parent 2b58780 commit 9fb8148

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public enum ErrorMessageID {
104104
EnumCaseDefinitionInNonEnumOwnerID,
105105
ExpectedTypeBoundOrEqualsID,
106106
ClassAndCompanionNameClashID,
107+
TailrecNotApplicableNeitherPrivateNorFinalID,
107108
;
108109

109110
public int errorNumber() {

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,6 +1777,7 @@ object messages {
17771777
val explanation =
17781778
hl"""A class marked with the ${"final"} keyword cannot be extended"""
17791779
}
1780+
17801781
case class EnumCaseDefinitionInNonEnumOwner(owner: Symbol)(implicit ctx: Context)
17811782
extends Message(EnumCaseDefinitionInNonEnumOwnerID) {
17821783
val kind = "Syntax"
@@ -1817,4 +1818,14 @@ object messages {
18171818
| - ${other.owner} defines ${other}"""
18181819
}
18191820
}
1821+
1822+
case class TailrecNotApplicableNeitherPrivateNorFinal(owner: Symbol)(implicit ctx: Context)
1823+
extends Message(TailrecNotApplicableNeitherPrivateNorFinalID) {
1824+
val kind = "Syntax"
1825+
val msg = hl"TailRec optimisation not applicable, ${owner} is neither `private` nor `final` so can be overridden"
1826+
val explanation =
1827+
hl"""
1828+
|The `@tailrec` annotation can only be used on methods that are either `private` or `final`.
1829+
"""
1830+
}
18201831
}

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

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

1617
/**
1718
* A Tail Rec Transformer
@@ -161,7 +162,7 @@ class TailRec extends MiniPhaseTransform with DenotTransformer with FullParamete
161162
})
162163
}
163164
case d: DefDef if d.symbol.hasAnnotation(defn.TailrecAnnot) || methodsWithInnerAnnots.contains(d.symbol) =>
164-
ctx.error("TailRec optimisation not applicable, method is neither private nor final so can be overridden", sym.pos)
165+
ctx.error(TailrecNotApplicableNeitherPrivateNorFinal(sym), sym.pos)
165166
d
166167
case d if d.symbol.hasAnnotation(defn.TailrecAnnot) || methodsWithInnerAnnots.contains(d.symbol) =>
167168
ctx.error("TailRec optimisation not applicable, not a method", sym.pos)

0 commit comments

Comments
 (0)