Skip to content

Commit 93503b0

Browse files
committed
part of #1589; error message for DesugarEnums.scala:47
1 parent 1f5343c commit 93503b0

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import core._
66
import util.Positions._, Types._, Contexts._, Constants._, Names._, NameOps._, Flags._
77
import SymDenotations._, Symbols._, StdNames._, Annotations._, Trees._
88
import Decorators._
9+
import dotty.tools.dotc.reporting.diagnostic.messages.EnumCaseDefinitionInNonEnumOwner
910
import collection.mutable.ListBuffer
1011
import util.Property
1112
import typer.ErrorReporting._
@@ -32,7 +33,7 @@ object DesugarEnums {
3233
/** Is enum case `tree` situated in a companion object of an enum class? */
3334
def enumCaseIsLegal(tree: Tree)(implicit ctx: Context): Boolean = (
3435
ctx.owner.is(ModuleClass) && enumClass.derivesFrom(defn.EnumClass)
35-
|| { ctx.error(em"case not allowed here, since owner ${ctx.owner} is not an `enum' object", tree.pos)
36+
|| { ctx.error(EnumCaseDefinitionInNonEnumOwner(), tree.pos)
3637
false
3738
}
3839
)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public enum ErrorMessageID {
100100
NoReturnFromInlineID,
101101
ReturnOutsideMethodDefinitionID,
102102
UncheckedTypePatternID,
103+
EnumCaseDefinitionInNonEnumOwnerID,
103104
;
104105

105106
public int errorNumber() {

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1748,7 +1748,7 @@ object messages {
17481748
val explanation =
17491749
hl"you have to provide either ${"class"}, ${"trait"}, ${"object"}, or ${"enum"} definitions after qualifiers"
17501750
}
1751-
1751+
17521752
case class NoReturnFromInline(owner: Symbol)(implicit ctx: Context)
17531753
extends Message(NoReturnFromInlineID) {
17541754
val kind = "Syntax"
@@ -1770,4 +1770,21 @@ object messages {
17701770
|"""
17711771
}
17721772

1773+
case class EnumCaseDefinitionInNonEnumOwner()(implicit ctx: Context)
1774+
extends Message(EnumCaseDefinitionInNonEnumOwnerID) {
1775+
val kind = "Syntax"
1776+
val msg = em"case not allowed here, since owner ${ctx.owner} is not an `enum' object"
1777+
val explanation = {
1778+
1779+
hl"""
1780+
| ${"case"} is only allowed at this place if the surrounding object is the companion object of an `enum class`.
1781+
| If you wanted to create an enumeration, make sure that the corresponding class has the `enum` keyword.
1782+
| Otherwise you might have forgotten `class` or `object` after this `enum`.
1783+
|
1784+
| See http://dotty.epfl.ch/docs/reference/enums/enums.html for more details on enumerations.
1785+
""".stripMargin
1786+
}
1787+
1788+
}
1789+
17731790
}

0 commit comments

Comments
 (0)