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

ScalaDoc fails to re-substitute macros for inherited members #9785

Closed
scabug opened this issue May 18, 2016 · 5 comments
Closed

ScalaDoc fails to re-substitute macros for inherited members #9785

scabug opened this issue May 18, 2016 · 5 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented May 18, 2016

Problem

ScalaDoc should expand redefined macros in documentation for inherited members to the macro bodies from the subclass, but expands the redefined macros to their old bodies from the superclass instead.

Background

According to https://wiki.scala-lang.org/display/SW/Tags+and+Annotations, documentation inheritance and ScalaDoc macros should interact as follows (emphasis mine):

{quote}If a comment containing macros is inherited, macros will normally be extended to the bodies defined in the super-class. However, It is possible to redefine macros in the sub-class (using @define tags with the same names) such that macros in inherited comments are extended to the redefined bodies. This happens even if members are inherited, as opposed to being overridden or implemented.{quote}

Contrary to this description, Scaladoc only expands macros to their redefined bodies if members are overriden or implemented, but not if members are merely inherited.

Example

package doctest

/** @define macro Super */
class Super {
  /** $macro */ def inherited
  /** $macro */ def implemented
  /** $macro */ def overriden {}
}

/** @define macro Sub */
class Sub extends Super {
  def implemented {}
  override def overriden {}
}

Expected Behavior

In the documentation of Sub, all three methods should be documented with "Sub".

Actual Behavior

In the documentation of Sub, only overriden and implemented (the methods that show up in the body of Sub) are documented with "Sub", but inherited (the method that is only inherited) is documented with "Super".

Screenshot of Actual Behavior

!inherited.png|thumbnail!

@scabug
Copy link
Author

scabug commented May 18, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9785?orig=1
Reporter: Tillmann Rendel (toxaris)
Attachments:

  • inherited.png (created on May 18, 2016 9:36:22 PM UTC, 35791 bytes)
  • MapLike.png (created on May 18, 2016 10:10:50 PM UTC, 83203 bytes)

@scabug
Copy link
Author

scabug commented May 18, 2016

Tillmann Rendel (toxaris) said:
I noted that this bug also affects the documentation of the standard library. The first example I found is the following:

scala.collection.IterableLike uses a macro in the documentation of toIterable:

/** A template trait for iterable collections of type `Iterable[A]`.
 *   ...
 *  @define coll iterable collection
 */
trait IterableLike[+A, +Repr] extends ... {
  ...
  /** Returns this $coll as an iterable collection.
   *  ...
   */
  override /*TraversableLike*/ def toIterable: Iterable[A] =
    thisCollection
  ...
}

In MapLike, the macro is redefined:

/** A template trait for maps, which associate keys with values.
 *  ...
 *  @define coll map
 *  ...
 */
trait MapLike[A, +B, +This <: ...] extends ...
    with IterableLike[(A, B), This] with ... {
  ...
}

And toIterable is simply inherited from IterableLike (not overriden).

I think the documentation for MapLike.toIterable is supposed to read "Returns this map as an iterable collection." Instead, it reads "Returns this iterable collection as an iterable collection." (Emphasis mine in both cases).

This happens because ScalaDoc fails to re-substitute the macro $coll when inheriting the documentation for toIterable.

I don't know whether this only affects such stylistic issues or whether some of the more substantial macros in the standard library documentation are also instantiated wrongly.

!MapLike.png|thumbnail!

The screenshot shows how the documentation of different methods uses different language to refer to the "this map":

  • toArray and toBuffer use "this map"
  • toIndexedSeq uses "this traversable or iterator"
  • toIterable and toIterator use "this iterable collection"

I think that "this map" should be uses consistently, and that this bug disables the documentation macro machinery that is supposed to achieve this consistency.

@Lasering
Copy link

Lasering commented Jun 8, 2020

@janekdb Is this something that someone without a lot experience in compilers can tackle?

@SethTisue
Copy link
Member

SethTisue commented Jun 11, 2020

@Lasering absolutely, yes!

this could be a good ticket to tackle if you want to get your feet wet, at least a little, with compiler internals. most tickets labeled "scaladocs tool" are like that. and a great deal of scalac/scaladoc-tool work doesn't require training/experience in compilers. https://www.scaladays.org/2018/new-york/schedule/you-are-a-scala-contributor has some recommendations on reading/videos to start with, beginning with https://docs.scala-lang.org/overviews/reflection/symbols-trees-types.html

but if exposure to scalac internals isn't appealing to you, pick a different ticket :-)

@Lasering
Copy link

@SethTisue I found and solved the problem.

Lasering/scala@2c5b873

I can make the PR.

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

4 participants