Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve inheritance rules for scaladoc comments #10043

Open
scabug opened this issue Nov 10, 2016 · 3 comments
Open

Improve inheritance rules for scaladoc comments #10043

scabug opened this issue Nov 10, 2016 · 3 comments

Comments

@scabug
Copy link

scabug commented Nov 10, 2016

An issue that complicates generating suitable scaladoc comments for the collections library (as witnessed in #6947) is the current inheritance scheme for scaladoc comments. Take this example:

trait A { /** A */ def f: Any }
trait B extends A { def f: Any = ??? }
trait C extends A { /** C */ def f: Any }
trait D extends B with C
trait D2 extends B with C { /** D */ def f: Any }

As (correctly) listed by scaladoc, the linear supertypes of D and D2 are: C, B, A, AnyRef, Any.

Quiz: What do the comments for D.f and D2.f show?

Perhaps surprisingly, they both show "A" with definition classes B -> A. The reason is that scaladoc prefers concrete method definitions over abstract ones, such that both comments are taken from B.f which inherits the comment from A.f. This makes it impossible to refine comments independent of implementations in an inheritance pattern with intertwined definition and implementation traits, as used by the collections library. The only way to get a new comment for D.f is through a concrete definition:

trait D3 extends B with C { /** D */ def f: Any = super.f }

This situation could be improved by always following the linearization order for the enclosing template. In the example, C comes before B and A in the linearization of D, therefore D.f inherits the comment from C.f.

An alternative proposal by @adriaanm is to keep the current scheme of preferring cocrete definitions over abstract definitions but treat definitions with a new doc comment as concrete for this purpose.

@scabug
Copy link
Author

scabug commented Nov 10, 2016

Imported From: https://issues.scala-lang.org/browse/SI-10043?orig=1
Reporter: @szeiger
Affected Versions: 2.12.0
See #6947

@scabug
Copy link
Author

scabug commented Nov 10, 2016

@adriaanm said:
My proposal is to use lookup as usual, except to determine concrete/deferred by looking at the doc comment instead of the definitions's RHS. Linearization would act as the tie breaker in case of diamond inheritance.

@scabug
Copy link
Author

scabug commented Nov 11, 2016

@szeiger said:
A related issue arises for "@define" tags. For example, adding a scaladoc comment which references "$coll" to GenMapLike does not use GenMapLike's definition of "coll" when the comment is viewed in GenMap ("trait GenMap... extends GenMapLike... with GenIterable...").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants