File tree Expand file tree Collapse file tree 3 files changed +15
-1
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 3 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -102,6 +102,7 @@ public enum ErrorMessageID {
102
102
UncheckedTypePatternID ,
103
103
ExtendFinalClassID ,
104
104
EnumCaseDefinitionInNonEnumOwnerID ,
105
+ TailrecNotApplicableNeitherPrivateNorFinalID ,
105
106
;
106
107
107
108
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"
@@ -1786,4 +1787,15 @@ object messages {
1786
1787
|If you want to create an ${" enum" } case, make sure the corresponding ${" enum class" } exists
1787
1788
|and has the ${" enum" } keyword. """
1788
1789
}
1790
+
1791
+
1792
+ case class TailrecNotApplicableNeitherPrivateNorFinal (owner : Symbol )(implicit ctx : Context )
1793
+ extends Message (TailrecNotApplicableNeitherPrivateNorFinalID ) {
1794
+ val kind = " Syntax"
1795
+ val msg = hl " TailRec optimisation not applicable, ${owner} is neither `private` nor `final` so can be overridden "
1796
+ val explanation =
1797
+ hl """
1798
+ |The `@tailrec` annotation can only be used on methods that are either `private` or `final`.
1799
+ """
1800
+ }
1789
1801
}
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
@@ -162,7 +163,7 @@ class TailRec extends MiniPhaseTransform with DenotTransformer with FullParamete
162
163
})
163
164
}
164
165
case d : DefDef if d.symbol.hasAnnotation(defn.TailrecAnnot ) || methodsWithInnerAnnots.contains(d.symbol) =>
165
- ctx.error(" TailRec optimisation not applicable, method is neither private nor final so can be overridden " , sym.pos)
166
+ ctx.error(TailrecNotApplicableNeitherPrivateNorFinal (sym) , sym.pos)
166
167
d
167
168
case d if d.symbol.hasAnnotation(defn.TailrecAnnot ) || methodsWithInnerAnnots.contains(d.symbol) =>
168
169
ctx.error(" TailRec optimisation not applicable, not a method" , sym.pos)
You can’t perform that action at this time.
0 commit comments