Skip to content

Commit

Permalink
fix(#16610): warn Scaladoc on multiple cases
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
i10416 committed Jan 28, 2024
1 parent 1716bcd commit 5c252cb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3955,6 +3955,13 @@ object Parsers {
if (in.token == COMMA) {
in.nextToken()
val ids = commaSeparated(() => termIdent())
in.getDocComment(start).foreach: comm =>
warning(
em"""Ambiguous Scaladoc comment on multiple cases is ignored.
|Remove the comment or make separate cases and 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:11:2 -------------------------------------------------------------------------------
11 | /** // warn
| ^
| Ambiguous Scaladoc comment on multiple cases is ignored.
| Remove the comment or make separate cases to add Scaladoc comments to each of them.
15 changes: 15 additions & 0 deletions tests/warn/i16610.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Description of enum
*/
enum MyEnum {

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

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

0 comments on commit 5c252cb

Please sign in to comment.