File tree Expand file tree Collapse file tree 3 files changed +14
-1
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 3 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -104,6 +104,7 @@ public enum ErrorMessageID {
104
104
EnumCaseDefinitionInNonEnumOwnerID ,
105
105
ExpectedTypeBoundOrEqualsID ,
106
106
ClassAndCompanionNameClashID ,
107
+ TailrecNotApplicableNeitherPrivateNorFinalID ,
107
108
;
108
109
109
110
public int errorNumber () {
Original file line number Diff line number Diff line change @@ -1777,6 +1777,7 @@ object messages {
1777
1777
val explanation =
1778
1778
hl """ A class marked with the ${" final" } keyword cannot be extended """
1779
1779
}
1780
+
1780
1781
case class EnumCaseDefinitionInNonEnumOwner (owner : Symbol )(implicit ctx : Context )
1781
1782
extends Message (EnumCaseDefinitionInNonEnumOwnerID ) {
1782
1783
val kind = " Syntax"
@@ -1817,4 +1818,14 @@ object messages {
1817
1818
| - ${other.owner} defines ${other}"""
1818
1819
}
1819
1820
}
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
+ }
1820
1831
}
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import Symbols._
12
12
import Types ._
13
13
import NameKinds .TailLabelName
14
14
import TreeTransforms .{MiniPhaseTransform , TransformerInfo }
15
+ import reporting .diagnostic .messages .TailrecNotApplicableNeitherPrivateNorFinal
15
16
16
17
/**
17
18
* A Tail Rec Transformer
@@ -161,7 +162,7 @@ class TailRec extends MiniPhaseTransform with DenotTransformer with FullParamete
161
162
})
162
163
}
163
164
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)
165
166
d
166
167
case d if d.symbol.hasAnnotation(defn.TailrecAnnot ) || methodsWithInnerAnnots.contains(d.symbol) =>
167
168
ctx.error(" TailRec optimisation not applicable, not a method" , sym.pos)
You can’t perform that action at this time.
0 commit comments