aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Typer.scala
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-08-27 00:30:07 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-10-06 17:45:12 +0200
commit5463b7a9d42ece31409526ce192d263f7f55e047 (patch)
treebbdacab4ef724e42a45f3e59c0fa8acdf3ba3b3e /src/dotty/tools/dotc/typer/Typer.scala
parentea24c55fdc7b3310a7f9911b408647701b5799fa (diff)
downloaddotty-5463b7a9d42ece31409526ce192d263f7f55e047.tar.gz
dotty-5463b7a9d42ece31409526ce192d263f7f55e047.tar.bz2
dotty-5463b7a9d42ece31409526ce192d263f7f55e047.zip
Fix cooking of docstrings
Diffstat (limited to 'src/dotty/tools/dotc/typer/Typer.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala45
1 files changed, 34 insertions, 11 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 181f5bd7c..2a8e7da9a 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -11,6 +11,7 @@ import Scopes._
import Denotations._
import ProtoTypes._
import Contexts._
+import Comments._
import Symbols._
import Types._
import SymDenotations._
@@ -1246,7 +1247,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
val dummy = localDummy(cls, impl)
val body1 = typedStats(impl.body, dummy)(inClassContext(self1.symbol))
- typedUsecases(body1.map(_.symbol), self1.symbol)
+ if (ctx.settings.Ydocrun.value)
+ typedUsecases(body1.map(_.symbol), self1.symbol)
checkNoDoubleDefs(cls)
val impl1 = cpy.Template(impl)(constr1, parents1, self1, body1)
@@ -1536,16 +1538,37 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
tpd.cpy.DefDef(mdef)(rhs = Inliner.bodyToInline(mdef.symbol)) ::
Inliner.removeInlineAccessors(mdef.symbol)
- def typedUsecases(syms: List[Symbol], owner: Symbol)(implicit ctx: Context): Unit =
- for {
- sym <- syms
- usecase <- ctx.docbase.docstring(sym).map(_.usecases).getOrElse(Nil)
- List(tpdTree) = typedStats(usecase.untpdCode :: Nil, owner)
- } yield {
- if (tpdTree.isInstanceOf[tpd.DefDef])
- usecase.tpdCode = tpdTree.asInstanceOf[tpd.DefDef]
- else
- ctx.error("Couldn't compile `@usecase`", usecase.codePos)
+ def typedUsecases(syms: List[Symbol], owner: Symbol)(implicit ctx: Context): Unit = {
+ val relevantSyms = syms.filter(ctx.docbase.docstring(_).isDefined)
+ relevantSyms.foreach { sym =>
+ expandParentDocs(sym)
+ val usecases = ctx.docbase.docstring(sym).map(_.usecases).getOrElse(Nil)
+
+ usecases.foreach { usecase =>
+ enterSymbol(createSymbol(usecase.untpdCode))
+
+ typedStats(usecase.untpdCode :: Nil, owner) match {
+ case List(df: tpd.DefDef) => usecase.tpdCode = df
+ case _ => ctx.error("`@usecase` was not a valid definition", usecase.codePos)
+ }
+ }
+ }
+ }
+
+ import dotty.tools.dottydoc.model.comment.CommentExpander
+ val expander = new CommentExpander {}
+ def expandParentDocs(sym: Symbol)(implicit ctx: Context): Unit =
+ ctx.docbase.docstring(sym).foreach { cmt =>
+ def expandDoc(owner: Symbol): Unit = {
+ expander.defineVariables(sym)
+ val newCmt = Comment(cmt.pos, expander.expandedDocComment(sym, owner, cmt.raw))
+ ctx.docbase.addDocstring(sym, Some(newCmt))
+ }
+
+ if (sym ne NoSymbol) {
+ expandParentDocs(sym.owner)
+ expandDoc(sym.owner)
+ }
}
def typedExpr(tree: untpd.Tree, pt: Type = WildcardType)(implicit ctx: Context): Tree =