1

I'm working in a project that uses Scala 2.10 and I have this code that uses an expanded or annonymous function e.g.

multiTest("Tarn to Mc", fixture1) {
   case (capRaw: (Double, Int), /* .. more arguments .. */ callPut: Tuple2[Double, Double]) =>
   // test body implementation
}

for both cases above I get the warning:

non-variable type argument Double in type pattern (Double, Int) is unchecked since it is eliminated by erasure

How can I get rid of this warning without having to define my own class UDTs?

SkyWalker
  • 13,729
  • 18
  • 91
  • 187

2 Answers2

1

Try:

multiTest("Tarn to Mc", fixture1) {
   case ((d: Double, i: Int), /* .. more arguments .. */ callPut: Tuple2[Double, Double]) =>
   // test body implementation
}

This might remove the compilation warning.

1

While Barrameda's answer is entirely reasonable, you can often do better by allowing the compiler to check the types itself. It looks like you went with the first solution to your previous question, but if you use the second one with

case class FixtureTable[A](heading: Map[String, String], values: Seq[A])
def multiTest[A](testName: String, fixture: FixtureTable[A])(fun: A => Unit)(implicit pos: source.Position): Unit = ...

you wouldn't get the warning, because the compiler already knows capRaw has type (Double, Int) and doesn't need to insert a check (and of course, for the same reason you can just write case capRaw => without the type).

Community
  • 1
  • 1
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
  • Hahaha good inter-Q catch ... since everything is working now I will pospone doing what you propose but I will try to implement your proposed cleaner solution. However, as you pointed out before it is hard to implement the generic cross product using the template parameter. For now I simply use `Product` instead of `[A]` – SkyWalker Sep 30 '16 at 12:25