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

Scala ApiDocs method signatures are inconsistent with method signatures in source #6046

Open
scabug opened this issue Jul 8, 2012 · 9 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Jul 8, 2012

For example, the method signature for Map[P,Q].map is:

class Map[P,Q]
def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That

...however, in the apidocs, the signature is given as:
def map[B, That](f: ((A, B)) ⇒ B)(implicit bf: CanBuildFrom[Map[A, B], B, That]): That

The first signature is the congruent with functioning code in 2.8.x and 2.9.x libraries. At first glance this problem seems to be inherent in the generation of the apidocs from the source.

@scabug
Copy link
Author

scabug commented Jul 8, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6046?orig=1
Reporter: Michael Joya (mjml)
Affected Versions: 2.9.2
See #3448

@scabug
Copy link
Author

scabug commented Jul 11, 2012

@VladUreche said:
We need to have alpha-renaming in scaladoc to fix this systematically. OR, to fix this particular occurrence, we need to rename the Map type parameters to [K,V] for key and value, making the signature look like:

def map[B, That](f: ((K, V))  B)(implicit bf: CanBuildFrom[Map[K, V], B, That]): That 

and the usecase:

def map[B, That](f: ((K, V))  B): Map[B] // which is incorrect again, see SI-3448

What do you think?

And now the long explanation why this signature gets there:
Method map in scala.collection.Map comes from TraversableLike (which implements the declarations in FilterMonadic and GenTraversableLike):

trait TraversableLike[+A, +Repr] {
  ...
  def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = {
    val b = bf(repr)
    b.sizeHint(this)
    for (x <- this) b += f(x)
    b.result
  }
  ...
}

Now, map is inherited into scala.collection.Map by way of:

trait Map[A, +B] extends Iterable[(A, B)] with ...
trait Iterable[+A] extends ... with IterableLike[A, Iterable[A]] 
trait IterableLike[+A, +Repr] extends ... with TraversableLike[A, Repr] with ...

But as you can see, Map extends Iterable[(A, B)], and thus substitutes A to ((Map's)A, (Map's)B). And now it's obvious how the signature is generated:

def map[B, That](f: ((Map's)A, (Map's)B) => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = ...

@scabug
Copy link
Author

scabug commented Jul 11, 2012

@VladUreche said:
Alex, what would it take to alpha-rename all Map classes' type params from {{Map[A, B]}} to {{Map[K, V]}}? Would it mean touching 10 classes, 100 classes? Or would break other ppl's code?

@scabug
Copy link
Author

scabug commented Jul 11, 2012

@axel22 said:
Probably some 20-30 occurrences according to: grep -r "(trait|class) [A-Za-z]*Map[".

I don't think renaming the type parameters of Map classes should break any code.

@scabug
Copy link
Author

scabug commented Jul 11, 2012

@adriaanm said:
I vote against such a symptomatic fix. See #6057 for unexpected collateral damage of renaming type params

@scabug
Copy link
Author

scabug commented Jul 11, 2012

@VladUreche said:
Great! Let's aim for the rename then, as alpha-substitution in scaladoc has no way of getting into 2.10.
I'll have a look today and if I have trouble with the rename, I'll ask for help.

@scabug
Copy link
Author

scabug commented Jul 11, 2012

@VladUreche said:
Not sure I understand what's happening in #6057, but it looks like an error that should be fixed and that shouldn't stop us from renaming.

@scabug
Copy link
Author

scabug commented Jul 11, 2012

@axel22 said (edited on Jul 11, 2012 12:11:39 PM UTC):
Agreed with Adriaan here. First, it was a convention to use [A, B] as type parameters. Second, I think the risks of introducing breakage similar as in the linked ticket outweigh the gain of renaming..

@scabug
Copy link
Author

scabug commented Jul 11, 2012

@VladUreche said:
Hmpfff... Let me see what I can do about alpha-renaming then.

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