Unexpected productIterator order

74 views
Skip to first unread message

Simon Adameit

unread,
Mar 19, 2015, 1:15:00 PM3/19/15
to scala-l...@googlegroups.com
Hello,

we noticed some strange behaviour of productIterator in Scala 2.11.5:

case class Data(a: String, b: String, `a-some`: String)
val m = Data("1", "2", "3")
assert(m.productIterator.mkString(", ") == "1, 2, 3")

Result: "1, [3, 2]" did not equal "1, [2, 3]"

"a-some" can be any mangled symbol with an "a" prefix.

Is the order of productIterator on case classes guaranteed to be in parameter order? If so, this seems to be a bug. Can anyone reproduce it?

Regards,
Simon Adameit

Simon Schäfer

unread,
Mar 19, 2015, 1:44:52 PM3/19/15
to scala-l...@googlegroups.com
Product.productElement (http://scala-lang.org/api/current/index.html#scala.Product@productElement%28n:Int%29:Any) says:

The nth element of this product, 0-based. In other words, for a product A(x1, ..., xk), returns x(n+1) where 0 < n < k.

Therefore, it is a bug in productElement. However, productIterator doesn't specify ordering...

Regards,
Simon Adameit
--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-languag...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jason Zaugg

unread,
Mar 19, 2015, 3:09:16 PM3/19/15
to scala-l...@googlegroups.com
This appears to have the same root cause as SI-8831. I have added your example to that bug, I'll include it as a test case when we fix this.

For now the workaround is to avoid using backticked case class param names that start with the name of another parameter.

-jason
Reply all
Reply to author
Forward
0 new messages