Strange cast errors with Kotlin 1.0.2-1 and RxKotlin 0.60.0


In the follow code:

import rx.lang.kotlin.toObservable

fun main(vararg args: String) {
    val csv = listOf(
                arrayOf("key", "value1"),
                arrayOf("", "value2")

            .reduce(listOf<Array<String>>()) { list, row ->
                println("row ${listOf(*row)}")
                if (row[0].length == 0) {
                    // java.lang.ClassCastException: java.lang.String cannot be cast to [Ljava.lang.Object;
                    val key = list.last().get(0)
                    println("key $key")
                    row[0] = key
       // required cast: as List<Array<String>>
            }.forEach { println(it) }


compiler force me to cast “ as List<Array>” (inferred as List!)!) ), if I fix this error then run the application produces a ClassCastException.

How can I fix the code?


PS: build.gradle

apply plugin: 'kotlin'
apply plugin: 'application'


buildscript {
    ext.kotlin_version = '1.0.2-1'
    repositories {
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    compile 'io.reactivex:rxkotlin:0.60.0'

repositories {


Looks like you may have run into a flavor of where the call is resolving to try to add each element of the row array to the list rather than adding the Array<String> reference as a single element. Try using list.plusElement(row) in place of as noted in the comments on that issue.


Thanks for suggestion,
I’m going to investigate later.