Skip to content

Commit 76ee412

Browse files
committed
fix(#16610): warn Scaladoc on multiple cases
Before this commit, the compiler ignored Scaladoc comment on multiple enum cases without warning. This is partly expected because the case to which the doc is attached is ambiguous, but we should at least warn users that the comment is ignored by compiler due to ambiguity and they should take an action if they want the doc to be displayed.
1 parent 1716bcd commit 76ee412

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3955,6 +3955,13 @@ object Parsers {
39553955
if (in.token == COMMA) {
39563956
in.nextToken()
39573957
val ids = commaSeparated(() => termIdent())
3958+
in.getDocComment(start).foreach: comm =>
3959+
warning(
3960+
em"""Ambiguous Scaladoc comment on multiple cases is ignored.
3961+
|Remove the comment or make separate cases to add Scaladoc comments to each of them.""",
3962+
comm.span.start
3963+
)
3964+
39583965
PatDef(mods1, id :: ids, TypeTree(), EmptyTree)
39593966
}
39603967
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:11:2 -------------------------------------------------------------------------------
2+
11 | /** // 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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Description of enum
3+
*/
4+
enum MyEnum {
5+
6+
/**
7+
* Description of case 1
8+
*/
9+
case MyCase1
10+
11+
/** // warn
12+
* Description of case 2 and 3
13+
*/
14+
case MyCase2, MyCase3
15+
}

0 commit comments

Comments
 (0)