diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2012-12-10 12:46:13 +0100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2012-12-10 13:10:52 +0100 |
commit | e249f2eeb8451c1b754711294ed954c8de7775fb (patch) | |
tree | 2a202ea255ec265cee3f343bd4b76e8443f767a4 | |
parent | 0acb8a30c379f268e8a3e1340504530493a1a1dc (diff) | |
download | scala-e249f2eeb8451c1b754711294ed954c8de7775fb.tar.gz scala-e249f2eeb8451c1b754711294ed954c8de7775fb.tar.bz2 scala-e249f2eeb8451c1b754711294ed954c8de7775fb.zip |
SI-4922 Show default in Scaladoc for generic methods.
We must account for cloned symbols.
-rw-r--r-- | src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala | 11 | ||||
-rw-r--r-- | test/scaladoc/run/t4922.check | 1 | ||||
-rw-r--r-- | test/scaladoc/run/t4922.scala | 32 |
3 files changed, 43 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala b/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala index 3ae1210ebf..8ced574676 100644 --- a/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala +++ b/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala @@ -950,7 +950,16 @@ class ModelFactory(val global: Global, val settings: doc.Settings) { // units.filter should return only one element (currentRun.units filter (_.source.file == aSym.sourceFile)).toList match { case List(unit) => - (unit.body find (_.symbol == aSym)) match { + // SI-4922 `sym == aSym` is insufficent if `aSym` is a clone of symbol + // of the parameter in the tree, as can happen with type parametric methods. + def isCorrespondingParam(sym: Symbol) = ( + sym != null && + sym != NoSymbol && + sym.owner == aSym.owner && + sym.name == aSym.name && + sym.isParamWithDefault + ) + (unit.body find (t => isCorrespondingParam(t.symbol))) match { case Some(ValDef(_,_,_,rhs)) => makeTree(rhs) case _ => None } diff --git a/test/scaladoc/run/t4922.check b/test/scaladoc/run/t4922.check new file mode 100644 index 0000000000..619c56180b --- /dev/null +++ b/test/scaladoc/run/t4922.check @@ -0,0 +1 @@ +Done. diff --git a/test/scaladoc/run/t4922.scala b/test/scaladoc/run/t4922.scala new file mode 100644 index 0000000000..bce87ac980 --- /dev/null +++ b/test/scaladoc/run/t4922.scala @@ -0,0 +1,32 @@ +import scala.tools.nsc.doc.model._ +import scala.tools.partest.ScaladocModelTest + +object Test extends ScaladocModelTest { + + // Test code + override def code = """ + // This the default values should be displayed + + object Test { + def f (a: Any = "".isEmpty) = () + def g[A](b: A = null) = () + } + """ + + // no need for special settings + def scaladocSettings = "" + + def testModel(rootPackage: Package) = { + // get the quick access implicit defs in scope (_package(s), _class(es), _trait(s), object(s) _method(s), _value(s)) + import access._ + + val Test = rootPackage._object("Test") + val f = Test._method("f") + val g = Test._method("g") + + def assertEqual(s1: String, s2: String) = assert(s1 == s2, s1 + " == " + s2) + + assertEqual(f.valueParams(0)(0).defaultValue.get.expression, "\"\".isEmpty") + assertEqual(g.valueParams(0)(0).defaultValue.get.expression, "null") + } +}
\ No newline at end of file |