why are local extension properties not allowed, bu...
# getting-started
l
why are local extension properties not allowed, but functions are ?
Copy code
fun foo() {
	fun Int.x() = 42 //ok
	val Int.y = 42 //error
}
j
I don't know, but my guess would be that the
get()
syntax might be a problem in function bodies (they would not mix well with regular code). And extension properties can't be defined with backing fields like you did even in general, they always need a getter
l
makes sense
e
extension properties must always be getter (and setter) only, because they cannot modify the receiving class to add a backing field
I don't know why local extension properties are not allowed at all, they just desugar to function calls… oh well. I see a request from years ago: https://youtrack.jetbrains.com/issue/KT-23711
350 Views