Open pengmaokui opened 6 months ago
Scala 3 infers String, but the copying conversion is deprecated.
scala 2.13.12> test(Array[String]("jan", "feb", "mar", "april", "may", "jun")) // print
test[String](scala.Predef.copyArrayToImmutableIndexedSeq[String](scala.Array.apply[scala.Predef.String]("jan", "feb", "mar", "april", "may", "jun")(scala.reflect.`package`.materializeClassTag[String]()))) // : (implicit evidence$1: scala.reflect.ClassTag[String]): Unit
If you take the advice and use toIndexedSeq
, it will also infer String:
scala 2.13.12> test(Array[String]("jan", "feb", "mar", "april", "may", "jun")) // print
^
warning: method copyArrayToImmutableIndexedSeq in class LowPriorityImplicits2 is deprecated (since 2.13.0): implicit conversions from Array to immutable.IndexedSeq are implemented by copying; use `toIndexedSeq` explicitly if you want to copy, or use the more efficient non-copying ArraySeq.unsafeWrapArray
ArraySeq(jan, feb, mar, april, may, jun)
scala 2.13.12> test(Array[String]("jan", "feb", "mar", "april", "may", "jun").toIndexedSeq)
ArraySeq(jan, feb, mar, april, may, jun)
scala 2.13.12> test(Array("jan", "feb", "mar", "april", "may", "jun").toIndexedSeq)
ArraySeq(jan, feb, mar, april, may, jun)
Of the overloads of Array.apply
, the primitive versions are more specific than the generic.
Maybe Scala 3 defers inferring the type until after it finds the conversion. (Just a guess.)
Reproduction steps
Scala version: (2.13.12)
Problem
Compile not pass