diff options
author | Vlad Ureche <vlad.ureche@gmail.com> | 2012-07-02 20:42:38 +0200 |
---|---|---|
committer | Vlad Ureche <vlad.ureche@gmail.com> | 2012-07-16 23:41:44 +0200 |
commit | 891769fae541513d68ce7a8e84b7213472c333c9 (patch) | |
tree | 63815332d3636198229cc7da7bdd7307e04d89bb | |
parent | 8779ade6f57ef15a04babf9715bc7ca4cbbdc425 (diff) | |
download | scala-891769fae541513d68ce7a8e84b7213472c333c9.tar.gz scala-891769fae541513d68ce7a8e84b7213472c333c9.tar.bz2 scala-891769fae541513d68ce7a8e84b7213472c333c9.zip |
Scaladoc: workaround for untypical Map usecases
SI-3448 partial fix:
This enables a workaround for the fact that Map takes two type params
while $Coll takes only one. But it doesn't fix the problem though,
as there's one more piece missing from the puzzle - we need to adjust
the `Coll`s in {immutable, mutable, concurrent}.Map to something that
makes sense for the usecase. And that's not possible. But I'm
committing this nevertheless, maybe other projects can benefit from it.
And for SI-3448, the solution lies in automatic usecase generation,
whenever that will be ready.
-rwxr-xr-x | src/compiler/scala/tools/nsc/ast/DocComments.scala | 19 | ||||
-rw-r--r-- | test/scaladoc/run/SI-3448.check | 1 | ||||
-rw-r--r-- | test/scaladoc/run/SI-3448.scala | 38 |
3 files changed, 50 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/DocComments.scala b/src/compiler/scala/tools/nsc/ast/DocComments.scala index b2d6800ebb..19af01bda8 100755 --- a/src/compiler/scala/tools/nsc/ast/DocComments.scala +++ b/src/compiler/scala/tools/nsc/ast/DocComments.scala @@ -513,23 +513,25 @@ trait DocComments { self: Global => tstr } - val aliasExpansions: List[Type] = + // the Boolean tells us whether we can normalize: if we found an actual type, then yes, we can normalize, else no, + // use the synthetic alias created for the variable + val aliasExpansions: List[(Type, Boolean)] = for (alias <- aliases) yield lookupVariable(alias.name.toString.substring(1), site) match { case Some(repl) => val repl2 = cleanupVariable(repl) val tpe = getType(repl2, alias.name.toString) - if (tpe != NoType) tpe + if (tpe != NoType) (tpe, true) else { val alias1 = alias.cloneSymbol(rootMirror.RootClass, alias.rawflags, newTypeName(repl2)) - typeRef(NoPrefix, alias1, Nil) + (typeRef(NoPrefix, alias1, Nil), false) } case None => - typeRef(NoPrefix, alias, Nil) + (typeRef(NoPrefix, alias, Nil), false) } - def subst(sym: Symbol, from: List[Symbol], to: List[Type]): Type = - if (from.isEmpty) sym.tpe + def subst(sym: Symbol, from: List[Symbol], to: List[(Type, Boolean)]): (Type, Boolean) = + if (from.isEmpty) (sym.tpe, false) else if (from.head == sym) to.head else subst(sym, from.tail, to.tail) @@ -537,8 +539,9 @@ trait DocComments { self: Global => def apply(tp: Type) = mapOver(tp) match { case tp1 @ TypeRef(pre, sym, args) if (sym.name.length > 1 && sym.name.startChar == '$') => subst(sym, aliases, aliasExpansions) match { - case TypeRef(pre1, sym1, _) => - typeRef(pre1, sym1, args) + case (TypeRef(pre1, sym1, _), canNormalize) => + val tpe = typeRef(pre1, sym1, args) + if (canNormalize) tpe.normalize else tpe case _ => tp1 } diff --git a/test/scaladoc/run/SI-3448.check b/test/scaladoc/run/SI-3448.check new file mode 100644 index 0000000000..619c56180b --- /dev/null +++ b/test/scaladoc/run/SI-3448.check @@ -0,0 +1 @@ +Done. diff --git a/test/scaladoc/run/SI-3448.scala b/test/scaladoc/run/SI-3448.scala new file mode 100644 index 0000000000..a2d3f59596 --- /dev/null +++ b/test/scaladoc/run/SI-3448.scala @@ -0,0 +1,38 @@ +import scala.tools.nsc.doc.model._ +import scala.tools.partest.ScaladocModelTest + +object Test extends ScaladocModelTest { + + // Working around the fact that usecases have the form Coll[T] and not Coll[T, U], as required by Map + override def code = """ + /** + * @define Coll C[T] + */ + class C[T] { + /** + * @usecase def foo[T]: $Coll[T] + */ + def foo[T: Numeric]: C[T] + } + + + /** + * @define Coll D1[T] + */ + class D[U, T] extends C[T] { + protected type D1[Z] = D[U, Z] + } + """ + + // 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._ + + // just need to check the member exists, access methods will throw an error if there's a problem + assert(rootPackage._class("D")._method("foo").resultType.name == "D[U, T]", + rootPackage._class("D")._method("foo").resultType.name + " == D[U, T]") + } +}
\ No newline at end of file |