Skip to content

Commit a05b0e5

Browse files
authored
Merge pull request #4751 from dotty-staging/fix/doc-cook-empty-classes
Cook comment on empty classes
2 parents 0a8a963 + 33c3a74 commit a05b0e5

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,7 @@ class Typer extends Namer
15361536

15371537
// Expand comments and type usecases if `-Ycook-comments` is set.
15381538
if (ctx.settings.YcookComments.value) {
1539-
cookComments(body1.map(_.symbol), self1.symbol)(ctx.localContext(cdef, cls).setNewScope)
1539+
cookComments(cls :: body1.map(_.symbol), self1.symbol)(ctx.localContext(cdef, cls).setNewScope)
15401540
}
15411541

15421542
checkNoDoubleDeclaration(cls)

doc-tool/test/SimpleComments.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
11
package dotty.tools
22
package dottydoc
33

4+
import model.internal._
5+
46
import org.junit.Test
57
import org.junit.Assert._
68

79
class TestSimpleComments extends DottyDocTest {
810

11+
@Test def cookCommentEmptyClass = {
12+
val source =
13+
"""
14+
|package scala
15+
|
16+
|/**
17+
| * An empty trait: $Variable
18+
| *
19+
| * @define Variable foobar
20+
| */
21+
|trait Test""".stripMargin
22+
23+
checkSource(source) { packages =>
24+
packages("scala") match {
25+
case PackageImpl(_, _, _, List(trt), _, _, _, _) =>
26+
assert(trt.comment.isDefined, "Lost comment in transformations")
27+
assert(trt.comment.get.body.contains("An empty trait: foobar"))
28+
assert(trt.name == "Test", s"Incorrect name after transform: ${trt.name}")
29+
}
30+
}
31+
}
32+
933
@Test def simpleComment = {
1034
val source =
1135
"""

0 commit comments

Comments
 (0)