Skip to content

Commit cfb04ef

Browse files
committed
Added comments to local definitions. Closes 5527
1 parent fc2866e commit cfb04ef

File tree

3 files changed

+67
-3
lines changed

3 files changed

+67
-3
lines changed

src/compiler/scala/tools/nsc/ast/parser/Parsers.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2967,10 +2967,10 @@ self =>
29672967
val annots = annotations(true)
29682968
val pos = in.offset
29692969
val mods = (localModifiers() | implicitMod) withAnnotations annots
2970-
val defs =
2970+
val defs = joinComment( // for SI-5527
29712971
if (!(mods hasFlag ~(Flags.IMPLICIT | Flags.LAZY))) defOrDcl(pos, mods)
2972-
else List(tmplDef(pos, mods))
2973-
2972+
else List(tmplDef(pos, mods)))
2973+
29742974
in.token match {
29752975
case RBRACE | CASE => defs :+ (Literal(Constant()) setPos o2p(in.offset))
29762976
case _ => defs

test/files/run/t5527.check

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[[syntax trees at end of parser]]// Scala source: newSource1
2+
package <empty> {
3+
abstract trait Test extends scala.ScalaObject {
4+
def $init$() = {
5+
()
6+
};
7+
def sth: scala.Unit = {
8+
/** Some comment here */
9+
object Maybe extends scala.ScalaObject {
10+
def <init>() = {
11+
super.<init>();
12+
()
13+
};
14+
/** Some comment inside */
15+
def nothing() = ()
16+
};
17+
()
18+
}
19+
}
20+
}
21+

test/files/run/t5527.scala

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import scala.tools.partest._
2+
import java.io._
3+
import scala.tools.nsc._
4+
import scala.tools.nsc.util.CommandLineParser
5+
import scala.tools.nsc.doc.{Settings, DocFactory}
6+
import scala.tools.nsc.reporters.ConsoleReporter
7+
8+
object Test extends DirectTest {
9+
10+
override def extraSettings: String = "-usejavacp -Xprint:parser -Yrangepos -Ystop-after:parser -d " + testOutput.path
11+
12+
override def code = """
13+
// SI-5527
14+
trait Test {
15+
def sth {
16+
/** Some comment here */
17+
object Maybe {
18+
/** Some comment inside */
19+
def nothing() = ()
20+
}
21+
}
22+
}
23+
"""
24+
25+
override def show(): Unit = {
26+
// redirect err to out, for logging
27+
val prevErr = System.err
28+
System.setErr(System.out)
29+
compile()
30+
System.setErr(prevErr)
31+
}
32+
33+
override def newCompiler(args: String*): Global = {
34+
// we want the Scaladoc compiler here, because it keeps DocDef nodes in the tree
35+
val settings = new Settings(_ => ())
36+
val command = new ScalaDoc.Command((CommandLineParser tokenize extraSettings) ++ args.toList, settings)
37+
new DocFactory(new ConsoleReporter(settings), settings).compiler
38+
}
39+
40+
override def isDebug = false // so we don't get the newSettings warning
41+
}
42+
43+

0 commit comments

Comments
 (0)