Skip to content

Introduce CaseClassCannotExtendsEnum message to replace error string from Checking #5023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ public enum ErrorMessageID {
MatchCaseOnlyNullWarningID,
ImportRenamedTwiceID,
TypeTestAlwaysSucceedsID,
TermMemberNeedsNeedsResultTypeForImplicitSearchID
TermMemberNeedsNeedsResultTypeForImplicitSearchID,
CaseClassCannotExtendEnumID
;

public int errorNumber() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2120,4 +2120,10 @@ object messages {
|To avoid this error, give `$cycleSym` an explicit type.
|""".stripMargin
}

case class CaseClassCannotExtendEnum(cls: Symbol)(implicit ctx: Context) extends Message(CaseClassCannotExtendEnumID) {
override def kind: String = "Syntax"
override def msg: String = hl"""normal case $cls in ${cls.owner} cannot extend an enum"""
override def explanation: String = ""
}
}
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ trait Checking {
cls.owner.isTerm &&
(cls.owner.flagsUNSAFE.is(Case) || cls.owner.name == nme.DOLLAR_NEW)
if (!cdef.mods.isEnumCase && !isEnumAnonCls)
ctx.error(em"normal case $cls in ${cls.owner} cannot extend an enum", cdef.pos)
ctx.error(CaseClassCannotExtendEnum(cls), cdef.pos)
}

/** Check that all references coming from enum cases in an enum companion object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ class ErrorMessagesTests extends ErrorMessagesTest {
implicit val ctx: Context = ictx
assertMessageCount(1, messages)
val errorMsg = messages.head
assertEquals("normal case class Bar in package <empty> cannot extend an enum", errorMsg.msg)
val CaseClassCannotExtendEnum(cls) :: Nil = messages
assertEquals("Bar", cls.name.show)
assertEquals("<empty>", cls.owner.name.show)
}

@Test def typeMismatch =
Expand Down