Skip to content

inferred varargs type constructor creates implicit conversion non-uniformity #6529

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

Open
scabug opened this issue Oct 16, 2012 · 2 comments
Open
Labels

Comments

@scabug
Copy link

scabug commented Oct 16, 2012

package object foo {
  import scala.collection.generic.FilterMonadic
  implicit def imp1[A](xs: TraversableOnce[A])                 = new { def sfor(f: A => Any) = xs foreach f }
  implicit def imp2[A, Coll](xs: FilterMonadic[A, Coll])       = new { def fmfor(f: A => Any) = xs foreach f }
  implicit def imp3[A, CC[X] <: TraversableOnce[X]](xs: CC[A]) = new { def ccfor(f: A => Any) = xs foreach f }
}

package foo {
  class A {
    def f1(xs: Seq[Int]) = xs sfor println   // compiles
    def f2(xs: Int*)     = xs sfor println   // compiles
    def f3(xs: Seq[Int]) = xs fmfor println  // compiles
    def f4(xs: Int*)     = xs fmfor println  // compiles
    def f5(xs: Seq[Int]) = xs ccfor println  // compiles
    def f6(xs: Int*)     = xs ccfor println  // fails
    // ./a.scala:15: error: value ccfor is not a member of Int*
    //     def f6(xs: Int*)     = xs ccfor println  // fails
    //                               ^
    // one error found
  }
}

This is not an idle interest, because there are a lot of methods like this:

def f(xs: Foo*) = xs something g

Attempting to move "something" off of Traversable and into an extension method displays bugs like this in stark relief.

@scabug
Copy link
Author

scabug commented Oct 16, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6529?orig=1
Reporter: @paulp

@scabug
Copy link
Author

scabug commented Oct 16, 2012

@paulp said:
Also, one could reasonably ask why it infers "*" as a type constructor in the first place. Shouldn't this always be Seq?

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