Skip to content

Fix issues with enterBlock for comment parsing #1213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1879,7 +1879,7 @@ object Parsers {
in.nextToken()
TypeDef(name, tparams, typ()).withMods(mods).setComment(docstring)
case SUPERTYPE | SUBTYPE | SEMI | NEWLINE | NEWLINES | COMMA | RBRACE | EOF =>
TypeDef(name, tparams, typeBounds()).withMods(mods)
TypeDef(name, tparams, typeBounds()).withMods(mods).setComment(docstring)
case _ =>
syntaxErrorOrIncomplete("`=', `>:', or `<:' expected")
EmptyTree
Expand Down
6 changes: 3 additions & 3 deletions src/dotty/tools/dotc/parsing/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ object Scanners {
/** All doc comments as encountered, each list contains doc comments from
* the same block level. Starting with the deepest level and going upward
*/
private[this] var docsPerBlockStack: List[List[Comment]] = List(List())
private[this] var docsPerBlockStack: List[List[Comment]] = List(Nil)

/** Adds level of nesting to docstrings */
def enterBlock(): Unit =
docsPerBlockStack = Nil ::: docsPerBlockStack
docsPerBlockStack = List(Nil) ::: docsPerBlockStack

/** Removes level of nesting for docstrings */
def exitBlock(): Unit = docsPerBlockStack = docsPerBlockStack match {
case x :: xs => List(List())
case x :: Nil => List(Nil)
case _ => docsPerBlockStack.tail
}

Expand Down
30 changes: 30 additions & 0 deletions test/test/DottyDocParsingTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -456,4 +456,34 @@ class DottyDocParsingTests extends DottyDocTest {
}
}
}

@Test def withExtends = {
val source =
"""
|trait Trait1
|/** Class1 */
|class Class1 extends Trait1
""".stripMargin

import dotty.tools.dotc.ast.untpd._
checkFrontend(source) {
case p @ PackageDef(_, Seq(_, c: TypeDef)) =>
checkDocString(c.rawComment, "/** Class1 */")
}
}

@Test def withAnnotation = {
val source =
"""
|/** Class1 */
|@SerialVersionUID(1)
|class Class1
""".stripMargin

import dotty.tools.dotc.ast.untpd._
checkFrontend(source) {
case p @ PackageDef(_, Seq(c: TypeDef)) =>
checkDocString(c.rawComment, "/** Class1 */")
}
}
} /* End class */