Should this be reported as an issue of Intellij ID...
# getting-started
e
Should this be reported as an issue of Intellij IDEA or Kotlin Compiler? The details are in the thread
This simple function
Copy code
fun finalFloor(instructions: String): Int =
    instructions.sumOf { ch: Char ->
        when (ch) {
            '(' -> 1
            ')' -> -1
            else -> 0
        }
    }
does not compile
image.png
But when I specify this
as Int
to resolve the ambiguity, I get warning from Intellij IDEA
image.png
I think that IntelliJ warns incorrectly in this case
toInt()
is incorrectly reported as well
https://youtrack.jetbrains.com/projects/KT/issues/KT-46360/Type-inference-fails-to-infer[…]n-ambiguity-TypeVariableT-Int-Long I think it's related. Ended up with
Copy code
fun finalFloor(instructions: String): Long =
    instructions.sumOf { ch: Char ->
        when (ch) {
            '(' -> 1L
            ')' -> -1L
            else -> 0L
        }
    }
which compiles. Btw it's for https://adventofcode.com/2015/day/1
k
It's supposedly fixed in 2.2. Are you using an earlier version?
e
Yes, it's fixed in 2.2. I was using the old 2.1 version indeed, thanks