Skip to content

Commit 6b9f543

Browse files
committed
SI-5730 hide constructors of sealed abstract classes in scaladoc
Sealed abstract classes (like `List`) have a primary constructor, public by default. It can never be called by external code but it shows up in the scaladoc as a nice `new List()` construtor... If a class is only abstract, the constructor is still useful because people can subclass and call it. If it is only sealed (i.e. effectively final), then it is the normal constructor of a final class. But sealed *and* abstract makes documenting the constructor useless. This should remove the misleading constructors of `List`, `Double`, `Option` and others from the scaladoc.
1 parent f7c3c6b commit 6b9f543

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

src/scaladoc/scala/tools/nsc/doc/model/ModelFactory.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,8 +753,10 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
753753
})
754754
}
755755
else if (bSym.isConstructor)
756-
if (conversion.isDefined)
757-
None // don't list constructors inherted by implicit conversion
756+
if (conversion.isDefined || (bSym.enclClass.isAbstract && (bSym.enclClass.isSealed || bSym.enclClass.isFinal)))
757+
// don't list constructors inherited by implicit conversion
758+
// and don't list constructors of abstract sealed types (they cannot be accessed anyway)
759+
None
758760
else
759761
Some(new NonTemplateParamMemberImpl(bSym, conversion, useCaseOf, inTpl) with Constructor {
760762
override def isConstructor = true

test/scaladoc/run/t5730.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Done.

test/scaladoc/run/t5730.scala

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import scala.tools.nsc.doc.base._
2+
import scala.tools.nsc.doc.model._
3+
import scala.tools.partest.ScaladocModelTest
4+
5+
object Test extends ScaladocModelTest {
6+
7+
override def code = """
8+
package scala.test.scaladoc.T5730
9+
10+
/**
11+
* A link:
12+
*
13+
* [[scala.Option$ object Option]].
14+
*/
15+
sealed abstract class A
16+
17+
case object B extends A
18+
19+
abstract final class C
20+
"""
21+
22+
def scaladocSettings = ""
23+
24+
def testModel(rootPackage: Package) = {
25+
// get the quick access implicit defs in scope (_package(s), _class(es), _trait(s), object(s) _method(s), _value(s))
26+
import access._
27+
28+
val p = rootPackage._package("scala")._package("test")._package("scaladoc")._package("T5730")
29+
30+
val a = p._class("A")
31+
val c = p._class("C")
32+
33+
assert(a.constructors.isEmpty, s"there should be no constructors, found: ${a.constructors}")
34+
assert(c.constructors.isEmpty, s"there should be no constructors, found: ${c.constructors}")
35+
}
36+
}

0 commit comments

Comments
 (0)