I’ve never understood why core types usually don’t define natural implicit: Unit, Option, Either, Tuple defining the natural implicits would good in my view. I have often wanted (and implemented) version of an implicit Option (prefer Some, fallback to None) and Either (prefer Right, fallback to Left).
Afaik DummyImplicit is basically required due to how Java handles type erasure/methods. Apart from that there is no real use for it (from what I have seen).
The compiler cannot do this, because it alters the binary API. So binary compatibility would be extremely unstable.
Also it can’t work when mixing in a class two such methods coming from two different parents, since they would have the same erased signature before mixing.
This is much better, but Is it possible to do this automatically with a @unique annotation, so it will act like an @alpha(signature) that uses some kind of string signature according to the type signature of the definition before erasure? That will allow preserving binary compatibility, no?
E.g. @unique def foo(arg1 : Int, arg2 : String, arg3 : String*) : Unit
will act like @alpha("`foo : (Int, String, Seq[String]) => Unit`") def foo(arg1 : Int, arg2 : String, arg3 : String*) : Unit
No, that won’t work in cases of overriding relationships. It’s possible for a method A.m to override B.m, yet they have different types before erasure. An @unique that derives a name based on the signatures before erasure would not work in those situations.
and class B extends it, trying to override its methods. What would happen if the writers of B accidentally swap method names in the alpha annotation?
class B extends A {
@alpha("fooInt") override def foo(ps: String*) = ???
@alpha("fooString") override def foo(ps: Int*) = ???
}
Correct me if I’m wrong, but if you then have code like this, it will call fooInt instead of fooString:
val b: A = new B()
b.foo("Will", "this", "call", "fooInt?")
Currently, class B doesn’t compile because the alpha annotation can’t be used for double definitions yet, but once that is fixed, it won’t have any issue with external and internal names being different, so it might actually compile and then fail once run.