Unresolved Reference (in when)


#1

Hello,

I’ve been playing a little bit with Kotlin.

I get an unresolved reference error with the “Some#(…)” for Some.

I guess this is something trivial :slight_smile:

public open class Option<T>

public class None<T>: Option<T>()

public class Some<T>(val s: T): Option<T>() {

  fun map(f: (T) -> T): Option<T> {
  return Some(f(s))
  }

  fun toString(): jet.String {
  return “Option($s)”
  }
}

fun main(args: Array<String>): Unit {
  when(Some(“s”)) {
  is Some#(val s is String) -> println(s)
  else -> println(“Something else”)
  }
}


Best
Stephan


The Blog for Developers - http://codemonkeyism.com
http://twitter.com/codemonkeyism

#2

Pattern matching is unsupported, and we are deferring this feature until some next version of the language. Sorry.


#3

BTW, check out this example, it will help you:

https://github.com/abreslav/introduction-to-kotlin/blob/master/kotlin-examples/src/_06_smart_cast/Eval.kt#L52


#4

Thanks.

I was following this page:

http://confluence.jetbrains.net/display/Kotlin/Pattern+matching


#5

Fixed. Thanks.