Reduce function overload resolution problem

The code:

val pi = 4.0 * delta * (1.0..n).reduce{t, i ->

  val x = (i - 0.5) * delta

  t + 1.0 / (1.0 + x * x)

}

used to compile and execute fine. In preparing for my Devoxx UK 2015, having updated to plugin 0.12.540, I find I get:

ERROR: src/pi_sequential_reduce.kt: (15, 24) Overload resolution ambiguity:

public final fun times(other: kotlin.Byte): kotlin.Double defined in kotlin.Double

kotlin.deprecated public final fun times(other: kotlin.Char): kotlin.Double defined in kotlin.Double

public final fun times(other: kotlin.Double): kotlin.Double defined in kotlin.Double

public final fun times(other: kotlin.Float): kotlin.Double defined in kotlin.Double

public final fun times(other: kotlin.Int): kotlin.Double defined in kotlin.Double

public final fun times(other: kotlin.Long): kotlin.Double defined in kotlin.Double

public final fun times(other: kotlin.Short): kotlin.Double defined in kotlin.Double

which is rather problematic. So the questions are:

  1. has something gone awry with the type inferencing with reduce; and
  2. any idea how to “fix” this for Friday?

Looks like a bug. Could you please file an issue about it?

Introducing value from reduce helps:

 
val r = (1.0..n).reduce { t, i ->
    val x = (i - 0.5) * delta
    t + 1.0 / (1.0 + x * x)
}
val pi = 4.0 * delta * r

Ilya,

Thanks for the quick response. I should have tried splitting the expression myself.

I have opened https://youtrack.jetbrains.com/issue/KT-8067