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 implicits: multiple conversions may lead to duplicate members #9620
Comments
Imported From: https://issues.scala-lang.org/browse/SI-9620?orig=1
|
@VladUreche said (edited on Jan 9, 2016 6:21:44 PM UTC): object Boo {
implicit class BooCharIsFoo(boo: Boo[Char]) extends Foo[/* >>> */Nothing/* <<< */]
implicit class BooLongIsFoo(boo: Boo[Long]) extends Foo[/* >>> */AnyRef /* <<< */]
} As an alternative, we could show the signature of The only sane approach I can think of is to add a scaladoc annotation that instructs the inferencer to ignore the implicit conversion -- this way, we can hide very specific conversions. WDYT? |
@felixmulder said (edited on Feb 6, 2016 10:10:23 AM UTC): object Boo {
/**
* @hideImplicitConversion
*/
implicit class BooCharIsFoo(boo: Boo[Char]) extends Foo[Char]
} What I mean by this is: that we would want to hide each implicit conversion explicitly - not all of them right? |
@VladUreche said: |
@VladUreche said: |
@felixmulder said (edited on Feb 6, 2016 3:54:11 PM UTC): package a
import scala.annotation.hideImplicitConversion
trait Foo[S] {
def foo(t: S): Int = 123
}
trait Boo[T]
trait ShouldNotAppear
object Boo {
@hideImplicitConversion implicit class BooCharIsFoo(boo: Boo[ShouldNotAppear]) extends Foo[ShouldNotAppear]
implicit class BooLongIsFoo(boo: Boo[Long]) extends Foo[Long]
} I figured I could do something like this in def implicitShouldDocument(aSym: Symbol): Boolean = {
//...
&& !aSym.owner.annotations.map(_.symbol.nameString).contains("hideImplicitConversion")
} But unfortunately, the entities that have their owner set to the annotated implicit class - not one of them has the method So then I figured: maybe I can get the implicit class from the method (PS: #4949 on github is ready to be merged) PS2: I hope this approach enables us to mask stuff out in the Predef btw! |
@VladUreche said (edited on Feb 6, 2016 4:39:12 PM UTC): There are two places where we can annotate:
The problem with approach (1) is that we need a true annotation (as you showed before), since the doc comments are not persisted in the class files. While this is a working approach, it's probably not going to scale as well, because in some cases you may want to see the implicit conversion while in others you may want to hide it. The second approach places annotations at the implicit conversion targets. The good news is that, to get a page in Scaladoc for the entity, you need to have the source in the first place, so you also have the doc comment (since source entities have priority over classpath entities). So we can have an annotation in the doc comment. So now, instead of marking implicit def booIsFoo, you mark class Boo directly, saying you want to mask/hide implicit conversion booIsFoo. IMO, the second approach is markedly better, for two reasons:
Now, going back to your question: the owner is the lexically enclosing entity, such as trait Foo for method foo. Getting the subclasses of a class Foo is not possible realistically unless class Foo is final or sealed. Otherwise, we're in an open world, so any new code can subclass Foo, which makes it impossible to list all the subclasses of Foo. What I would imagine you want to do is: If you decide to keep going on this path, I can show you how you match the hideImplicitConversion as a symbol instead of by name. |
@felixmulder said: Just to take what you said and put it in an example: package a
trait Foo[S] {
def foo(t: S): Int = 123
}
/** Boo hides BooShouldNotAppearIsFoo
*
* @hideImplicitConversion BooShouldNotAppearIsFoo
*/
trait Boo[T]
trait ShouldNotAppear
object Boo {
implicit class BooShouldNotAppearIsFoo(boo: Boo[ShouldNotAppear]) extends Foo[ShouldNotAppear]
implicit class BooLongIsFoo(boo: Boo[Long]) extends Foo[Long]
} |
@VladUreche said: |
@VladUreche said: |
@gourlaysama said: |
Having multiple implicit conversions can lead to duplicate members in a template. This affects
scala.Array
which has its members duplicated 10 times.Here's a minimized example:
If you look at the result of running:
You see that the member
foo
intrait Boo
is duplicated:!double-def.png!
The reason is that it's added through the different conversions (
BooCharIsFoo
andBooLongIsFoo
).Now, if the signatures are identical, we could fold the "Implicit Member" information:
Now, what if the signatures are different, as is the case here? I don't know what to do. Any suggestions?
The text was updated successfully, but these errors were encountered: