Skip to content

Commit fb1ed0a

Browse files
committed
part of #1589; error message for DesugarEnums.scala:47
1 parent ba01fba commit fb1ed0a

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
@@ -99,6 +99,7 @@ public enum ErrorMessageID {
9999
MissingReturnTypeWithReturnStatementID,
100100
NoReturnFromInlineID,
101101
ReturnOutsideMethodDefinitionID,
102+
EnumCaseDefinitionInNonEnumOwnerID
102103
;
103104

104105
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
@@ -1736,7 +1736,7 @@ object messages {
17361736
val explanation =
17371737
hl"you have to provide either ${"class"}, ${"trait"}, ${"object"}, or ${"enum"} definitions after qualifiers"
17381738
}
1739-
1739+
17401740
case class NoReturnFromInline(owner: Symbol)(implicit ctx: Context)
17411741
extends Message(NoReturnFromInlineID) {
17421742
val kind = "Syntax"
@@ -1758,4 +1758,21 @@ object messages {
17581758
|"""
17591759
}
17601760

1761+
case class EnumCaseDefinitionInNonEnumOwner()(implicit ctx: Context)
1762+
extends Message(EnumCaseDefinitionInNonEnumOwnerID) {
1763+
val kind = "Syntax"
1764+
val msg = em"case not allowed here, since owner ${ctx.owner} is not an `enum' object"
1765+
val explanation = {
1766+
1767+
hl"""
1768+
| ${"case"} is only allowed at this place if the surrounding object is the companion object of an `enum class`.
1769+
| If you wanted to create an enumeration, make sure that the corresponding class has the `enum` keyword.
1770+
| Otherwise you might have forgotten `class` or `object` after this `enum`.
1771+
|
1772+
| See http://dotty.epfl.ch/docs/reference/enums/enums.html for more details on enumerations.
1773+
""".stripMargin
1774+
}
1775+
1776+
}
1777+
17611778
}

0 commit comments

Comments
 (0)