Skip to content

Commit b56f5c9

Browse files
committed
Merge pull request #1213 from felixmulder/topic/comment-parsing-fix
Fix issues with `enterBlock` for comment parsing
2 parents fcf0efe + dfcb26e commit b56f5c9

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1879,7 +1879,7 @@ object Parsers {
18791879
in.nextToken()
18801880
TypeDef(name, tparams, typ()).withMods(mods).setComment(docstring)
18811881
case SUPERTYPE | SUBTYPE | SEMI | NEWLINE | NEWLINES | COMMA | RBRACE | EOF =>
1882-
TypeDef(name, tparams, typeBounds()).withMods(mods)
1882+
TypeDef(name, tparams, typeBounds()).withMods(mods).setComment(docstring)
18831883
case _ =>
18841884
syntaxErrorOrIncomplete("`=', `>:', or `<:' expected")
18851885
EmptyTree

src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,15 @@ object Scanners {
180180
/** All doc comments as encountered, each list contains doc comments from
181181
* the same block level. Starting with the deepest level and going upward
182182
*/
183-
private[this] var docsPerBlockStack: List[List[Comment]] = List(List())
183+
private[this] var docsPerBlockStack: List[List[Comment]] = List(Nil)
184184

185185
/** Adds level of nesting to docstrings */
186186
def enterBlock(): Unit =
187-
docsPerBlockStack = Nil ::: docsPerBlockStack
187+
docsPerBlockStack = List(Nil) ::: docsPerBlockStack
188188

189189
/** Removes level of nesting for docstrings */
190190
def exitBlock(): Unit = docsPerBlockStack = docsPerBlockStack match {
191-
case x :: xs => List(List())
191+
case x :: Nil => List(Nil)
192192
case _ => docsPerBlockStack.tail
193193
}
194194

test/test/DottyDocParsingTests.scala

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,4 +456,34 @@ class DottyDocParsingTests extends DottyDocTest {
456456
}
457457
}
458458
}
459+
460+
@Test def withExtends = {
461+
val source =
462+
"""
463+
|trait Trait1
464+
|/** Class1 */
465+
|class Class1 extends Trait1
466+
""".stripMargin
467+
468+
import dotty.tools.dotc.ast.untpd._
469+
checkFrontend(source) {
470+
case p @ PackageDef(_, Seq(_, c: TypeDef)) =>
471+
checkDocString(c.rawComment, "/** Class1 */")
472+
}
473+
}
474+
475+
@Test def withAnnotation = {
476+
val source =
477+
"""
478+
|/** Class1 */
479+
|@SerialVersionUID(1)
480+
|class Class1
481+
""".stripMargin
482+
483+
import dotty.tools.dotc.ast.untpd._
484+
checkFrontend(source) {
485+
case p @ PackageDef(_, Seq(c: TypeDef)) =>
486+
checkDocString(c.rawComment, "/** Class1 */")
487+
}
488+
}
459489
} /* End class */

0 commit comments

Comments
 (0)