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
_* type annotation with implicit #4774
Comments
Imported From: https://issues.scala-lang.org/browse/SI-4774?orig=1
|
@soc said: object NoAnnotAllowed {
case class N[A](val n: A)
class My[A]
object My {
def apply[A](a: N[A]*) = new My[A]
// this apply causes the last expression to fail
def apply[A](s: String)(a: N[A]*) = new My[A]
}
implicit def anyToN[A](a: A): N[A] = N(a)
implicit def seqToN[A](s: Seq[A]): Seq[N[A]] = s map (x => N(x))
// works whether the first or both apply signatures are present
My(1, 2)
// tests the second apply
My("A")(1, 2)
My("A")(Seq(1, 2): _*)
// expected to work with or without the second apply
// but works only if the second apply is omitted
My(Seq(1, 2): _*)
} Error message: <console>:24: error: no `: _*' annotation allowed here
(such annotations are only allowed in arguments to *-parameters)
My(Seq(1, 2): _*)
^ |
@som-snytt said: Ascription helps pick the correct apply: My((Seq(1, 2): Seq[N[Int]]): _*) // "seems to work"
// But not the implicit you probably expect. You get:
My(Seq(anyToN(1), anyToN(2)): _*)
// instead of
My(seqToN(Seq(1,2)): _*)
// In the overtly erroneous case, it decides on:
My(anyToN(Seq(1,2): _*)) The difference in behavior begins with the overloaded apply; it rejects apply(String) and grabs onto the conversion Int=>N and doesn't let go. |
@lrytz said: object T {
case class N[A](val n: A)
implicit def anyToN[A](a: A): N[A] = N(a)
def foo[A](a: N[A]*) = 0
def foo[A](s: String)(a: N[A]*) = 1
foo(Seq(1, 2): _*)
} the invocation is transformed by the typer to foo[Int](T.this.anyToN[Int]((collection.this.Seq.apply[Int](1, 2): _*))) |
@JamesIry said: |
I'm about to extend a factory object (here object My) with a second signature for apply. It works as expected until I use the _* type annotation. Then I get the compiler error "no ': _*' annotation allowed here...". Attached my narrowed down version.
Dave thinks this is a bug: http://groups.google.com/group/scala-user/browse_thread/thread/c5a81c76301086fa.
The text was updated successfully, but these errors were encountered: