Pattern matching example failed to compile



I am trying out the example under “Pattern matching operators (is and !is)” from like this:


fun main(args: Array<String>) {
fun test(x : Any) {
     when (x) {
          is Int -> print(x)
          is List<Int> -> print(x.sum())
          !is Number -> print(“Not even a number”)
          else -> print(“can’t do anything”)

However this will not compile:


ERROR: /Users/zemian/apps/kotlinc-0.4.177/Test.kt: (9, 6) Cannot check for instance of erased type: jet.List<jet.Int>
ERROR: /Users/zemian/apps/kotlinc-0.4.177/Test.kt: (9, 27) Unresolved reference: sum
exec() finished with COMPILATION_ERROR return code

Even if I replace “print(x.sum())” with simply “print(x)”, I still get the first error.

Am I missing something?



Same problem as here?


Yes, it's the same problem. I fixed the example, it should have said "List<*> instead of List<Int>"