scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

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

Open scabug opened 12 years ago

scabug commented 12 years ago
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 commented 12 years ago

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

scabug commented 12 years ago

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