diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2017-02-10 15:29:35 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2017-04-04 13:29:38 +0200 |
commit | cb3e536f954d7e9a3eea528b07ffb768537f1383 (patch) | |
tree | 53cab8de26fa24af18324aea3a08917ffdc4636d /compiler/src/dotty/tools/dotc/parsing | |
parent | c245600ed4bfd4af6f2b45e8cae2cf5a63ddeaf0 (diff) | |
download | dotty-cb3e536f954d7e9a3eea528b07ffb768537f1383.tar.gz dotty-cb3e536f954d7e9a3eea528b07ffb768537f1383.tar.bz2 dotty-cb3e536f954d7e9a3eea528b07ffb768537f1383.zip |
Fix cheeky comment in nested scope
Diffstat (limited to 'compiler/src/dotty/tools/dotc/parsing')
-rw-r--r-- | compiler/src/dotty/tools/dotc/parsing/Scanners.scala | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala index a6f3936f8..ff5019dc9 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala @@ -178,12 +178,21 @@ object Scanners { /** All doc comments kept by their end position in a `Map` */ private[this] var docstringMap: SortedMap[Int, Comment] = SortedMap.empty - private[this] def addComment(comment: Comment): Unit = - docstringMap = docstringMap + (comment.pos.end -> comment) + private[this] def addComment(comment: Comment): Unit = { + val lookahead = lookaheadReader + def nextPos: Int = (lookahead.getc(): @switch) match { + case ' ' | '\t' => nextPos + case CR | LF | FF => + // if we encounter line delimitng whitespace we don't count it, since + // it seems not to affect positions in source + nextPos - 1 + case _ => lookahead.charOffset - 1 + } + docstringMap = docstringMap + (nextPos -> comment) + } /** Returns the closest docstring preceding the position supplied */ - def getDocComment(pos: Int): Option[Comment] = - docstringMap.to(pos).lastOption.map(_._2) + def getDocComment(pos: Int): Option[Comment] = docstringMap.get(pos) /** A buffer for comments */ val commentBuf = new StringBuilder @@ -589,10 +598,12 @@ object Scanners { val start = lastCharOffset def finishComment(): Boolean = { if (keepComments) { - val pos = Position(start, charOffset, start) + val pos = Position(start, charOffset - 1, start) val comment = Comment(pos, flushBuf(commentBuf)) - if (comment.isDocComment) addComment(comment) + if (comment.isDocComment) { + addComment(comment) + } } true |