Leaking this: fix for 'this' in enum class #KT-15835 Fixed

This commit is contained in:
Toshiaki Kameyama
2018-11-14 18:49:25 +09:00
committed by Mikhail Glukhikh
parent 14311e77c2
commit 2a03e1b3da
5 changed files with 80 additions and 3 deletions
+8
View File
@@ -0,0 +1,8 @@
// PROBLEM: none
enum class Foo {
ONE,
TWO;
val bar = Bar(<caret>this)
}
class Bar(val foo: Foo)
@@ -0,0 +1,20 @@
// PROBLEM: Leaking 'this' in constructor of enum class Foo (with overridable members)
// FIX: none
enum class Foo {
ONE {
override val x = 1
},
TWO {
override val x = 2
};
abstract val x: Int
val double = double(<caret>this)
}
fun double(foo: Foo) = foo.x * foo.x
fun test() {
Foo.ONE.double
Foo.TWO.double
}
@@ -0,0 +1,23 @@
// PROBLEM: Leaking 'this' in constructor of enum class Foo (with overridable members)
// FIX: none
enum class Foo : Bar {
ONE {
override val x = 1
},
TWO {
override val x = 2
};
val double = double(<caret>this)
}
interface Bar {
val x: Int
}
fun double(foo: Foo) = foo.x * foo.x
fun test() {
Foo.ONE.double
Foo.TWO.double
}