File tree Expand file tree Collapse file tree 3 files changed +16
-3
lines changed
test/dotty/tools/dotc/reporting Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ object DesugarEnums {
33
33
/** Is enum case `tree` situated in a companion object of an enum class? */
34
34
def enumCaseIsLegal (tree : Tree )(implicit ctx : Context ): Boolean = (
35
35
ctx.owner.is(ModuleClass ) && enumClass.derivesFrom(defn.EnumClass )
36
- || { ctx.error(EnumCaseDefinitionInNonEnumOwner (), tree.pos)
36
+ || { ctx.error(EnumCaseDefinitionInNonEnumOwner (ctx.owner ), tree.pos)
37
37
false
38
38
}
39
39
)
Original file line number Diff line number Diff line change @@ -1770,10 +1770,10 @@ object messages {
1770
1770
| """
1771
1771
}
1772
1772
1773
- case class EnumCaseDefinitionInNonEnumOwner ()(implicit ctx : Context )
1773
+ case class EnumCaseDefinitionInNonEnumOwner (owner : Symbol )(implicit ctx : Context )
1774
1774
extends Message (EnumCaseDefinitionInNonEnumOwnerID ) {
1775
1775
val kind = " Syntax"
1776
- val msg = em " case not allowed here, since owner ${ctx. owner} is not an `enum' object "
1776
+ val msg = em " case not allowed here, since owner ${owner} is not an `enum' object "
1777
1777
val explanation = {
1778
1778
1779
1779
hl """
Original file line number Diff line number Diff line change @@ -998,4 +998,17 @@ class ErrorMessagesTests extends ErrorMessagesTest {
998
998
val ReturnOutsideMethodDefinition (owner) :: Nil = messages
999
999
assertEquals(" object A" , owner.show)
1000
1000
}
1001
+
1002
+ @ Test def enumCaseDefinitionInNonEnumOwner =
1003
+ checkMessagesAfter(" frontend" ) {
1004
+ """ object Qux {
1005
+ | case Foo
1006
+ |}
1007
+ """ .stripMargin
1008
+ }.expect { (ictx, messages) =>
1009
+ implicit val ctx : Context = ictx
1010
+ assertMessageCount(1 , messages)
1011
+ val EnumCaseDefinitionInNonEnumOwner (owner) :: Nil = messages
1012
+ assertEquals(" object Qux" , owner.show)
1013
+ }
1001
1014
}
You can’t perform that action at this time.
0 commit comments