Skip to content
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

Backport "fix(#16610): warn ignored Scaladoc on multiple enum cases" to LTS #20983

Merged
merged 1 commit into from
Jul 3, 2024
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private sealed trait WarningSettings:
val XfatalWarnings: Setting[Boolean] = BooleanSetting("-Werror", "Fail the compilation if there are any warnings.", aliases = List("-Xfatal-warnings"))
val WvalueDiscard: Setting[Boolean] = BooleanSetting("-Wvalue-discard", "Warn when non-Unit expression results are unused.")
val WNonUnitStatement = BooleanSetting("-Wnonunit-statement", "Warn when block statements are non-Unit expressions.")

val WenumCommentDiscard = BooleanSetting("-Wenum-comment-discard", "Warn when a comment ambiguously assigned to multiple enum cases is discarded.")
val Wunused: Setting[List[ChoiceWithHelp[String]]] = MultiChoiceHelpSetting(
name = "-Wunused",
helpArg = "warning",
Expand Down
8 changes: 8 additions & 0 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3902,6 +3902,14 @@ object Parsers {
if (in.token == COMMA) {
in.nextToken()
val ids = commaSeparated(() => termIdent())
if ctx.settings.WenumCommentDiscard.value then
in.getDocComment(start).foreach: comm =>
warning(
em"""Ambiguous Scaladoc comment on multiple cases is ignored.
|Remove the comment or make separate cases to add Scaladoc comments to each of them.""",
comm.span.start
)

PatDef(mods1, id :: ids, TypeTree(), EmptyTree)
}
else {
Expand Down
5 changes: 5 additions & 0 deletions tests/warn/i16610.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Warning: tests/warn/i16610.scala:12:2 -------------------------------------------------------------------------------
12 | /** // warn
| ^
| Ambiguous Scaladoc comment on multiple cases is ignored.
| Remove the comment or make separate cases to add Scaladoc comments to each of them.
16 changes: 16 additions & 0 deletions tests/warn/i16610.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//> using options -Wenum-comment-discard
/**
* Description of enum
*/
enum MyEnum {

/**
* Description of case 1
*/
case MyCase1

/** // warn
* Description of case 2 and 3
*/
case MyCase2, MyCase3
}