Disallow extension properties with backing fields

#KT-1682 Fixed
This commit is contained in:
Alexander Udalov
2014-05-28 19:17:31 +04:00
parent ea31f372aa
commit d78d4bc44c
72 changed files with 297 additions and 578 deletions
@@ -0,0 +1,21 @@
class A {
var result = "Fail"
private var Int.foo: String
get() = result
private set(value) {
result = value
}
fun run(): String {
class O {
fun run() {
42.foo = "OK"
}
}
O().run()
return (-42).foo
}
}
fun box() = A().run()
@@ -1,11 +1,12 @@
class Test {
val Int.foo: String = "OK"
val Int.foo: String
get() = "OK"
fun test(): String {
return 1.foo
}
fun test(): String {
return 1.foo
}
}
fun box(): String {
return Test().test()
}
return Test().test()
}
@@ -1,16 +1,28 @@
class Test {
var Double.fooDouble: String = "fail"
var Long.fooLong: String = "fail"
var doubleStorage = "fail"
var longStorage = "fail"
fun test(): String {
val d = 1.0
d.fooDouble = "O"
val l = 1.toLong()
l.fooLong = "K"
return d.fooDouble + l.fooLong
}
var Double.foo: String
get() = doubleStorage
set(value) {
doubleStorage = value
}
var Long.bar: String
get() = longStorage
set(value) {
longStorage = value
}
fun test(): String {
val d = 1.0
d.foo = "O"
val l = 1L
l.bar = "K"
return d.foo + l.bar
}
}
fun box(): String {
return Test().test()
}
return Test().test()
}
@@ -1,13 +0,0 @@
class Test {
var Int.foo: String = "fail"
fun test(): String {
val i = 1
i.foo = "OK"
return i.foo
}
}
fun box(): String {
return Test().test()
}
@@ -1,15 +1,14 @@
class Test {
val Int.foo: String = "OK"
get() {
val a = $foo
return "OK"
}
val Int.foo: String
get() {
return "OK"
}
fun test(): String {
return 1.foo
}
fun test(): String {
return 1.foo
}
}
fun box(): String {
return Test().test()
}
return Test().test()
}
@@ -1,15 +1,14 @@
class Test {
private val Int.foo: String = "OK"
get() {
val a = $foo
return "OK"
}
private val Int.foo: String
get() {
return "OK"
}
fun test(): String {
return 1.foo
}
fun test(): String {
return 1.foo
}
}
fun box(): String {
return Test().test()
}
return Test().test()
}
@@ -1,16 +1,19 @@
class Test {
var Int.foo: String = "OK"
private set(str: String) {
$foo = str
}
var storage = "Fail"
fun test(): String {
val i = 1
i.foo = "OK"
return i.foo
}
var Int.foo: String
get() = storage
private set(str: String) {
storage = str
}
fun test(): String {
val i = 1
i.foo = "OK"
return i.foo
}
}
fun box(): String {
return Test().test()
}
return Test().test()
}
@@ -1,16 +1,19 @@
class Test {
var Int.foo: String = "fail"
set(str: String) {
$foo = str
}
var storage = "Fail"
fun test(): String {
val i = 1
i.foo = "OK"
return i.foo
}
var Int.foo: String
get() = storage
set(value) {
storage = value
}
fun test(): String {
val i = 1
i.foo = "OK"
return i.foo
}
}
fun box(): String {
return Test().test()
}
return Test().test()
}
@@ -1,5 +1,6 @@
val Int.foo: String = "OK"
val Int.foo: String
get() = "OK"
fun box(): String {
return 1.foo
}
return 1.foo
}
@@ -1,10 +1,22 @@
var Double.fooDouble: String = "fail"
var Long.fooLong: String = "fail"
var fooStorage = "Fail"
var barStorage = "Fail"
var Double.foo: String
get() = fooStorage
set(value) {
fooStorage = value
}
var Long.bar: String
get() = barStorage
set(value) {
barStorage = value
}
fun box(): String {
val d = 1.0
d.fooDouble = "O"
val l = 1.toLong()
l.fooLong = "K"
return d.fooDouble + l.fooLong
}
val d = 1.0
d.foo = "O"
val l = 1L
l.bar = "K"
return d.foo + l.bar
}
@@ -1,17 +0,0 @@
var Double.fooDouble: String = "fail"
set(str: String) {
$fooDouble = str
}
var Long.fooLong: String = "fail"
set(str: String) {
$fooLong = str
}
fun box(): String {
val d = 1.0
d.fooDouble = "O"
val l = 1.toLong()
l.fooLong = "K"
return d.fooDouble + l.fooLong
}
@@ -1,8 +0,0 @@
val Int.foo: String = "OK"
get() {
return $foo
}
fun box(): String {
return 1.foo
}
@@ -1,10 +0,0 @@
var Int.foo: String = "fail"
set(str: String) {
$foo = str
}
fun box(): String {
val i = 1
i.foo = "OK"
return i.foo
}