Skip to content

Commit 02ea1d8

Browse files
Backport "fix(#16610): warn ignored Scaladoc on multiple enum cases" to LTS (#20983)
Backports #19555 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents 70c73d9 + 9812065 commit 02ea1d8

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private sealed trait WarningSettings:
165165
val XfatalWarnings: Setting[Boolean] = BooleanSetting("-Werror", "Fail the compilation if there are any warnings.", aliases = List("-Xfatal-warnings"))
166166
val WvalueDiscard: Setting[Boolean] = BooleanSetting("-Wvalue-discard", "Warn when non-Unit expression results are unused.")
167167
val WNonUnitStatement = BooleanSetting("-Wnonunit-statement", "Warn when block statements are non-Unit expressions.")
168-
168+
val WenumCommentDiscard = BooleanSetting("-Wenum-comment-discard", "Warn when a comment ambiguously assigned to multiple enum cases is discarded.")
169169
val Wunused: Setting[List[ChoiceWithHelp[String]]] = MultiChoiceHelpSetting(
170170
name = "-Wunused",
171171
helpArg = "warning",

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3902,6 +3902,14 @@ object Parsers {
39023902
if (in.token == COMMA) {
39033903
in.nextToken()
39043904
val ids = commaSeparated(() => termIdent())
3905+
if ctx.settings.WenumCommentDiscard.value then
3906+
in.getDocComment(start).foreach: comm =>
3907+
warning(
3908+
em"""Ambiguous Scaladoc comment on multiple cases is ignored.
3909+
|Remove the comment or make separate cases to add Scaladoc comments to each of them.""",
3910+
comm.span.start
3911+
)
3912+
39053913
PatDef(mods1, id :: ids, TypeTree(), EmptyTree)
39063914
}
39073915
else {

tests/warn/i16610.check

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Warning: tests/warn/i16610.scala:12:2 -------------------------------------------------------------------------------
2+
12 | /** // warn
3+
| ^
4+
| Ambiguous Scaladoc comment on multiple cases is ignored.
5+
| Remove the comment or make separate cases to add Scaladoc comments to each of them.

tests/warn/i16610.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//> using options -Wenum-comment-discard
2+
/**
3+
* Description of enum
4+
*/
5+
enum MyEnum {
6+
7+
/**
8+
* Description of case 1
9+
*/
10+
case MyCase1
11+
12+
/** // warn
13+
* Description of case 2 and 3
14+
*/
15+
case MyCase2, MyCase3
16+
}

0 commit comments

Comments
 (0)