Indexed property in builder - convoluted but possible bug?


#1

In the following code, the last line does not compile. I'm not even sure if I like the way the syntax ends up looking, but should it work?!

package test


class Writer {
  fun something(v:String) {}
  fun set(n:String, v:String) {}
}


fun writer(init:Writer.() -> Unit) {
  val w=Writer()
  w.init()
}


fun test() {
  writer {
  something(“hello”)


  // aren’t these three equivalent?
  this[“name”]=“value” // ok
  set(“name”, “value”) // ok
  [“name”]=“value” // compile error
  }
}

Thanks, Alfie.


#2

It shouldn't work: you can't have a index operation [] on omitted "this". Use "this[]" instead.


#3

Ok, thanks! It's still a bit confusing to me why, but no big deal. There are more important things ;-)