File tree Expand file tree Collapse file tree 3 files changed +59
-5
lines changed
src/dotty/tools/dotc/parsing
test/dotty/tools/dotc/parsing
scala3doc-testcases/src/tests Expand file tree Collapse file tree 3 files changed +59
-5
lines changed Original file line number Diff line number Diff line change @@ -190,11 +190,7 @@ object Scanners {
190
190
private def addComment (comment : Comment ): Unit = {
191
191
val lookahead = lookaheadReader()
192
192
def nextPos : Int = (lookahead.getc(): @ switch) match {
193
- case ' ' | '\t ' => nextPos
194
- case CR | LF | FF =>
195
- // if we encounter line delimiting whitespace we don't count it, since
196
- // it seems not to affect positions in source
197
- nextPos - 1
193
+ case ' ' | '\t ' | CR | LF | FF => nextPos
198
194
case _ => lookahead.charOffset - 1
199
195
}
200
196
docstringMap = docstringMap + (nextPos -> comment)
@@ -854,6 +850,9 @@ object Scanners {
854
850
855
851
if (comment.isDocComment)
856
852
addComment(comment)
853
+ else
854
+ // "forward" doc comments over normal ones
855
+ getDocComment(start).foreach(addComment)
857
856
}
858
857
859
858
true
Original file line number Diff line number Diff line change @@ -474,6 +474,37 @@ class DocstringTests extends DocstringTest {
474
474
}
475
475
}
476
476
477
+
478
+ @ Test def overNL = {
479
+ val source =
480
+ """
481
+ |/** Class1 */
482
+ |
483
+ |class Class1
484
+ """ .stripMargin
485
+
486
+ import dotty .tools .dotc .ast .untpd ._
487
+ checkFrontend(source) {
488
+ case p @ PackageDef (_, Seq (c : TypeDef )) =>
489
+ checkDocString(c.rawComment.map(_.raw), " /** Class1 */" )
490
+ }
491
+ }
492
+
493
+ @ Test def overComment = {
494
+ val source =
495
+ """
496
+ |/** Class1 */
497
+ |// foo
498
+ |class Class1
499
+ """ .stripMargin
500
+
501
+ import dotty .tools .dotc .ast .untpd ._
502
+ checkFrontend(source) {
503
+ case p @ PackageDef (_, Seq (c : TypeDef )) =>
504
+ checkDocString(c.rawComment.map(_.raw), " /** Class1 */" )
505
+ }
506
+ }
507
+
477
508
@ Test def withAnnotation = {
478
509
val source =
479
510
"""
@@ -489,6 +520,22 @@ class DocstringTests extends DocstringTest {
489
520
}
490
521
}
491
522
523
+ @ Test def withAnnotationOverComment = {
524
+ val source =
525
+ """
526
+ |/** Class1 */
527
+ |// foo
528
+ |@SerialVersionUID(1)
529
+ |class Class1
530
+ """ .stripMargin
531
+
532
+ import dotty .tools .dotc .ast .untpd ._
533
+ checkFrontend(source) {
534
+ case p @ PackageDef (_, Seq (c : TypeDef )) =>
535
+ checkDocString(c.rawComment.map(_.raw), " /** Class1 */" )
536
+ }
537
+ }
538
+
492
539
@ Test def nestedComment = {
493
540
val source =
494
541
"""
Original file line number Diff line number Diff line change @@ -210,3 +210,11 @@ class Methods:
210
210
def primitives (a : Int , b : Double , c : Short ): Byte = 0
211
211
def strings (a : String ): String = " "
212
212
def arrays (a : Array [String ], b : Array [Int ]): Array [Double ] = ???
213
+
214
+ /** @define foo O's foo.
215
+ */
216
+ object O :
217
+
218
+ /** This is foo: $foo
219
+ */
220
+ def method (s : String ) = s
You can’t perform that action at this time.
0 commit comments