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

_* type annotation with implicit #4774

Open
scabug opened this issue Jul 6, 2011 · 5 comments
Open

_* type annotation with implicit #4774

scabug opened this issue Jul 6, 2011 · 5 comments
Assignees
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Jul 6, 2011

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.

@scabug
Copy link
Author

scabug commented Jul 6, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4774?orig=1
Reporter: Sonnenschein (sonnenschein)
Affected Versions: 2.9.0
Attachments:

@scabug
Copy link
Author

scabug commented May 12, 2012

@soc said:
Content of the attached file:

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): _*)
                     ^

@scabug
Copy link
Author

scabug commented May 12, 2012

@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.

@scabug
Copy link
Author

scabug commented Jul 5, 2012

@lrytz said:
simplified

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): _*)))

@scabug
Copy link
Author

scabug commented Aug 13, 2013

@JamesIry said:
2.10.3-RC1 is coming at the end of the week. If there's not likely to be a PR for this in the next couple of days let's kick it down the road to 2.10.4-RC1

@scabug scabug added the implicit label Apr 7, 2017
@scabug scabug added this to the Backlog milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants