Skip to content

Commit

Permalink
Merge pull request #9105 from forketyfork/2.13.x
Browse files Browse the repository at this point in the history
Fixed scaladoc failure on @throws tag when -implicits flag is on
  • Loading branch information
lrytz committed Jul 13, 2020
2 parents 29c8bfc + c1cfd77 commit daa51f5
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/scaladoc/scala/tools/nsc/doc/model/ModelFactory.scala
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,8 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
else
implicitlyConvertibleClassesCache.toList

// the implicit conversions are generated eagerly, but the members generated by implicit conversions are added
// lazily, on completeModel
val conversions: List[ImplicitConversionImpl] =
// the implicit conversions are generated lazily, on completeModel
lazy val conversions: List[ImplicitConversionImpl] =
if (settings.docImplicits) makeImplicitConversions(sym, this) else Nil

// members as given by the compiler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ import scala.tools.nsc.Reporting.WarningCategory
*
* class C extends B {
* def bar = 2
* class implicit
* class D
* }
*
* D def conv(a: A) = new C
* implicit def conv(a: A) = new C
* }
* }}}
*
Expand Down Expand Up @@ -103,10 +103,10 @@ trait ModelFactoryImplicitSupport {
// also keep empty conversions, so they appear in diagrams
// conversions = conversions.filter(!_.members.isEmpty)

val hiddenConversions: Seq[String] = thisFactory
val hiddenConversions: Set[String] = thisFactory
.comment(sym, inTpl.linkTarget, inTpl)
.map(_.hideImplicitConversions)
.getOrElse(Nil)
.map(_.hideImplicitConversions.toSet)
.getOrElse(Set.empty)

conversions = conversions filterNot { conv: ImplicitConversionImpl =>
hiddenConversions.contains(conv.conversionShortName) ||
Expand Down
9 changes: 9 additions & 0 deletions test/scaladoc/resources/implicits-throws-res.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package scala.test.scaladoc.implicits.throws {

/**
* @throws java.lang.Exception exception
*/
class A {
}

}
1 change: 1 addition & 0 deletions test/scaladoc/run/implicits-throws.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Done.
37 changes: 37 additions & 0 deletions test/scaladoc/run/implicits-throws.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import scala.language._
import scala.tools.nsc.doc.base.comment.Text
import scala.tools.nsc.doc.model._
import scala.tools.partest.ScaladocModelTest

/**
* Reproducer for https://github.com/scala/bug/issues/11021
* The @throws tag shouldn't cause an error when -implicits is enabled.
*/
object Test extends ScaladocModelTest {

// test a file instead of a piece of code
override def resourceFile = "implicits-throws-res.scala"

// start implicits
def scaladocSettings = "-implicits"

def testModel(root: Package) = {
// get the quick access implicit defs in scope (_package(s), _class(es), _trait(s), object(s) _method(s), _value(s))
import access._

val base = root._package("scala")._package("test")._package("scaladoc")._package("implicits")._package("throws")

val A = base._class("A")

val expectedComment = "exception"

A.comment
.flatMap(comment => comment.throws.get("java.lang.Exception"))
.flatMap(body => body.summary) match {
case Some(Text(actualComment)) =>
assert(actualComment == expectedComment, s"Expected: $expectedComment, actual: $actualComment")
case _ =>
assert(false, s"Failed to match the comment")
}
}
}

0 comments on commit daa51f5

Please sign in to comment.