S
S
sectronix2015-01-20 13:37:19
Scala
sectronix, 2015-01-20 13:37:19

Why does an exception occur when assigning a tuple?

I execute the code in the interpreter:

scala> val coords = Vector((0,0))
coords: scala.collection.immutable.Vector[(Int, Int)] = Vector((0,0))

Next I write I
scala> val (x, y) = coords(0)
get the longest stack, this is what is at the top:
java.lang.AssertionError: assertion failed: List(value _1$mcI$sp, value _1$mcI$sp, value _1$mcI$sp)
  at scala.reflect.internal.Symbols$Symbol.suchThat(Symbols.scala:1916)

However, there is a way to get around this behavior through assignment to an intermediate variable:
scala> val z = coords(0)
z: (Int, Int) = (0,0)

scala> val (x, y) = z
x: Int = 0
y: Int = 0

I have a suspicion that Scala cannot automatically infer the type in this expression.
val (x, y) = coords(0)
Am I understanding correctly or is there something else?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem, 2015-01-21
@sectronix

The reason is different. Roll back to version 2.11.4 or download the current trunk. There, the apply method was in the scope twice. In the current tank, this has already been fixed :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question