Hey guys, is there any reason that inline operator...
# language-proposals
m
Hey guys, is there any reason that inline operator set is not usable without this in lambda with a receiver? Imho, it could add to the DSL capabilities. Here is an example, where I think this might be useful
Copy code
class Json {
    val map : HashMap<String, Any> = HashMap()
}
inline operator fun <V> Json.set(key: String, value: V) {
    this.map[key] = value as Any // this is not of importance
}

fun obj(builder: Json.()->Unit): Json {
    val obj = Json()
    builder.invoke(obj)
    return obj
}

fun main(args: Array<String>) {
    obj {
        set("1", 1)    // this is ok
        this["2"] = 2  // this is ok
        ["3"] = 3      // this is not - Kotlin: Unsupported [Collection literals outside of annotation]
                       //             - Kotlin: Variable expected
    }
}
3
v
That would be stretching the syntax too much
b
["3"]
looks like a collection literal to me. Kotlin doesn’t have these, but your proposed syntax would eliminate the future possibility