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

Misleading type signatures in scaladoc for Map classes #6947

Closed
scabug opened this issue Jan 9, 2013 · 10 comments
Closed

Misleading type signatures in scaladoc for Map classes #6947

scabug opened this issue Jan 9, 2013 · 10 comments

Comments

@scabug
Copy link

scabug commented Jan 9, 2013

ScalaDoc is suggesting the type for foldLeft is,

foldLeft[B](z: B)(op: (B, (A, B)) ⇒ B): B

which is of course wrong and very misleading. It looks like there is a systematic error in doing a naive text substitution without doing proper variable capture. This leads to the B's being confused in this example. folding would be rather less useful were its return type bound to the value type in the Map.

@scabug
Copy link
Author

scabug commented Jan 9, 2013

Imported From: https://issues.scala-lang.org/browse/SI-6947?orig=1
Reporter: Declan Conlon (dconlon)
Other Milestones: 2.13.0-M1
See #9430

@scabug
Copy link
Author

scabug commented Jul 5, 2016

@szeiger said:
This problem is a lot more pervasive. Lots of inherited methods have a type parameter B which is indistinguishable from Map's own B in the docs.

I think the nicest solution, at least for Map, would be to rename the type parameters from A, B to K, V.

@scabug
Copy link
Author

scabug commented Jul 6, 2016

@szeiger said:
PR: scala/scala#5265

@scabug
Copy link
Author

scabug commented Nov 3, 2016

@szeiger said:
Reopening because use case signatures are still wrong. There is no automatic substitution of type parameters for these because the signatures are not real anyway, so we cannot reliably substitute anything. I expect we will have to duplicate all affected scaladoc comments from TraversableLike in MapLike in order to fix this.

@scabug
Copy link
Author

scabug commented Nov 9, 2016

@szeiger said:
After taking a closer look, it seems that substitutions are performed, and indeed many use case signatures look correct. The problem with some signatures is that substitution of the collection subtype leads to types like "GenMap" being substituted for "TraversableOnce", so you end up with "GenMap[B]". I didn't continue this investigation to find out why it doesn't substitute further to "GenMap[(K, V)]" like it does in other places because it is wrong either way. GenMap takes two type parameters.

@scabug
Copy link
Author

scabug commented Nov 11, 2016

@szeiger said:
I'm throwing the towel. Here's what I have to far: https://github.com/scala/scala/compare/2.12.x...szeiger:wip/map-scaladocs?expand=1

This only scratches the tip of the iceberg. Many interesting subclasses inherit the wrong comments and in many cases cannot be
fixed due to the way in which comments are inherited. The ones that could be fixed would require huge amounts of duplication.

In the end the problem with the scaladoc comments is the same as with nonsensical methods and slow implementations: Adding lots of stuff high up in the inheritance hierarchy means you end up with lots of stuff that doesn't really work.

@buzden
Copy link

buzden commented Sep 5, 2017

Short signature of the map() method of the Map class is also incorrect:

  • it says that this method returns Map[B] which is improssible due to Map has two type parameters;
  • it has wrong argument signature due to (K, V) is given as an argument for the argument-function instead of simply A.

@SethTisue
Copy link
Member

when https://github.com/scala/collection-strawman replaces the old collections in Scala 2.13 we could take a fresh look at this

@julienrf
Copy link

This is what we now get for foldLeft in Map:

image

I’ve checked all the places where we use @usecase and saw no misleading type signature. I think we can close this issue.

@julienrf
Copy link

(And this is also what we get for the map operation)

image

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

7 participants