From 33c3a7499615c04448db6fd46819424491ed4bd6 Mon Sep 17 00:00:00 2001 From: Martin Duhem Date: Mon, 2 Jul 2018 09:19:50 +0200 Subject: [PATCH] Cook comment on empty classes A class with an empty body wouldn't see its own comment cooked. --- .../src/dotty/tools/dotc/typer/Typer.scala | 2 +- doc-tool/test/SimpleComments.scala | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 115c4f8130a8..59d409e395f4 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1536,7 +1536,7 @@ class Typer extends Namer // Expand comments and type usecases if `-Ycook-comments` is set. if (ctx.settings.YcookComments.value) { - cookComments(body1.map(_.symbol), self1.symbol)(ctx.localContext(cdef, cls).setNewScope) + cookComments(cls :: body1.map(_.symbol), self1.symbol)(ctx.localContext(cdef, cls).setNewScope) } checkNoDoubleDeclaration(cls) diff --git a/doc-tool/test/SimpleComments.scala b/doc-tool/test/SimpleComments.scala index bc420feeb637..d38832cc4f79 100644 --- a/doc-tool/test/SimpleComments.scala +++ b/doc-tool/test/SimpleComments.scala @@ -1,11 +1,35 @@ package dotty.tools package dottydoc +import model.internal._ + import org.junit.Test import org.junit.Assert._ class TestSimpleComments extends DottyDocTest { + @Test def cookCommentEmptyClass = { + val source = + """ + |package scala + | + |/** + | * An empty trait: $Variable + | * + | * @define Variable foobar + | */ + |trait Test""".stripMargin + + checkSource(source) { packages => + packages("scala") match { + case PackageImpl(_, _, _, List(trt), _, _, _, _) => + assert(trt.comment.isDefined, "Lost comment in transformations") + assert(trt.comment.get.body.contains("An empty trait: foobar")) + assert(trt.name == "Test", s"Incorrect name after transform: ${trt.name}") + } + } + } + @Test def simpleComment = { val source = """