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 @@ -1758,10 +1758,10 @@ object messages {
1758
1758
| """
1759
1759
}
1760
1760
1761
- case class EnumCaseDefinitionInNonEnumOwner ()(implicit ctx : Context )
1761
+ case class EnumCaseDefinitionInNonEnumOwner (owner : Symbol )(implicit ctx : Context )
1762
1762
extends Message (EnumCaseDefinitionInNonEnumOwnerID ) {
1763
1763
val kind = " Syntax"
1764
- val msg = em " case not allowed here, since owner ${ctx. owner} is not an `enum' object "
1764
+ val msg = em " case not allowed here, since owner ${owner} is not an `enum' object "
1765
1765
val explanation = {
1766
1766
1767
1767
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