diff options
author | Dmitry Petrashko <dark@d-d.me> | 2016-04-11 15:03:58 +0200 |
---|---|---|
committer | Dmitry Petrashko <dark@d-d.me> | 2016-04-11 15:03:58 +0200 |
commit | b56f5c9620800adfaa27e359754be4b9a7aab4fe (patch) | |
tree | a8c1c4973fe3bec4b1cb5ae057e034695e97bc12 | |
parent | fcf0efe1d70bd71b212f07a5764196860a7c4148 (diff) | |
parent | dfcb26ec6806d361334f12cb31e574ef57b2f7c5 (diff) | |
download | dotty-b56f5c9620800adfaa27e359754be4b9a7aab4fe.tar.gz dotty-b56f5c9620800adfaa27e359754be4b9a7aab4fe.tar.bz2 dotty-b56f5c9620800adfaa27e359754be4b9a7aab4fe.zip |
Merge pull request #1213 from felixmulder/topic/comment-parsing-fix
Fix issues with `enterBlock` for comment parsing
-rw-r--r-- | src/dotty/tools/dotc/parsing/Parsers.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/parsing/Scanners.scala | 6 | ||||
-rw-r--r-- | test/test/DottyDocParsingTests.scala | 30 |
3 files changed, 34 insertions, 4 deletions
diff --git a/src/dotty/tools/dotc/parsing/Parsers.scala b/src/dotty/tools/dotc/parsing/Parsers.scala index cdfc366a7..ded17c67c 100644 --- a/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/src/dotty/tools/dotc/parsing/Parsers.scala @@ -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 diff --git a/src/dotty/tools/dotc/parsing/Scanners.scala b/src/dotty/tools/dotc/parsing/Scanners.scala index 7ebe63397..6fe86502f 100644 --- a/src/dotty/tools/dotc/parsing/Scanners.scala +++ b/src/dotty/tools/dotc/parsing/Scanners.scala @@ -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 } diff --git a/test/test/DottyDocParsingTests.scala b/test/test/DottyDocParsingTests.scala index 32cfaaddf..b09d048da 100644 --- a/test/test/DottyDocParsingTests.scala +++ b/test/test/DottyDocParsingTests.scala @@ -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 */ |