Skip to content

Commit

Permalink
IR Inliner: Tests for backing fields leakage through private inline funs
Browse files Browse the repository at this point in the history
^KT-71137
  • Loading branch information
ddolovov authored and qodana-bot committed Sep 5, 2024
1 parent 1507d26 commit fb4b1ad
Show file tree
Hide file tree
Showing 18 changed files with 258 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@ public class OK
/* TARGET use-site */ <this>.#k
public fun <set-k>(<set-?>: String)
/* TARGET use-site */ <this>.#k = <set-?>
internal inline fun initializeAndReadLateinitProperties(): String
/* ACCESSOR use-site */ access$<get-o>$p($this = <this>)
/* ACCESSOR use-site */ access$<set-o>($this = <this>, <set-?> = "O")
/* ACCESSOR use-site */ access$<get-o>$p($this = <this>)
/* ACCESSOR use-site */ access$<get-k>$p($this = <this>)
/* ACCESSOR use-site */ access$<get-k>$p($this = <this>)
/* ACCESSOR use-site */ access$<get-o>($this = <this>)
private inline fun doInitializeAndReadOK(): String
/* TARGET use-site */ <this>.#o
/* TARGET use-site */ <this>.<set-o>(<set-?> = "O")
/* TARGET use-site */ <this>.#o
/* TARGET use-site */ <this>.#k
/* TARGET use-site */ <this>.#k
/* TARGET use-site */ <this>.<get-o>()
internal inline fun initializeAndReadOK(): String
/* ACCESSOR use-site */ access$<get-o>$p($this = this)
/* ACCESSOR use-site */ access$<set-o>($this = this, <set-?> = "O")
/* ACCESSOR use-site */ access$<get-o>$p($this = this)
/* ACCESSOR use-site */ access$<get-k>$p($this = this)
/* ACCESSOR use-site */ access$<get-k>$p($this = this)
/* ACCESSOR use-site */ access$<get-o>($this = this)
/* ACCESSOR declaration */ internal /* static */ fun access$<get-o>($this: OK): String
/* TARGET use-site */ $this.<get-o>()
/* ACCESSOR declaration */ internal /* static */ fun access$<set-o>($this: OK, <set-?>: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@ public class OK
/* TARGET use-site */ <this>.#k
public fun <set-k>(<set-?>: String)
/* TARGET use-site */ <this>.#k = <set-?>
internal inline fun initializeAndReadLateinitProperties(): String
/* ACCESSOR use-site */ access$<get-o>$p($this = <this>)
/* ACCESSOR use-site */ access$<set-o>($this = <this>, <set-?> = "O")
/* ACCESSOR use-site */ access$<get-o>$p($this = <this>)
/* ACCESSOR use-site */ access$<get-k>$p($this = <this>)
/* ACCESSOR use-site */ access$<get-k>$p($this = <this>)
/* ACCESSOR use-site */ access$<get-o>($this = <this>)
private inline fun doInitializeAndReadOK(): String
/* TARGET use-site */ <this>.#o
/* TARGET use-site */ <this>.<set-o>(<set-?> = "O")
/* TARGET use-site */ <this>.#o
/* TARGET use-site */ <this>.#k
/* TARGET use-site */ <this>.#k
/* TARGET use-site */ <this>.<get-o>()
internal inline fun initializeAndReadOK(): String
/* ACCESSOR use-site */ access$<get-o>$p($this = this)
/* ACCESSOR use-site */ access$<set-o>($this = this, <set-?> = "O")
/* ACCESSOR use-site */ access$<get-o>$p($this = this)
/* ACCESSOR use-site */ access$<get-k>$p($this = this)
/* ACCESSOR use-site */ access$<get-k>$p($this = this)
/* ACCESSOR use-site */ access$<get-o>($this = this)
/* ACCESSOR declaration */ public /* static */ fun access$<get-o>($this: OK): String
/* TARGET use-site */ $this.<get-o>()
/* ACCESSOR declaration */ public /* static */ fun access$<set-o>($this: OK, <set-?>: String)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
// FILE: OK.kt
class OK {
private lateinit var x: String // never leaked
lateinit var y: String // never leaked

private lateinit var o: String
lateinit var k: String

internal inline fun initializeAndReadLateinitProperties(): String {
private inline fun doInitializeAndReadXY(): String {
if (::x.isInitialized) throw Error("Property 'x' already initialized")
x = "X"
if (!::x.isInitialized) throw Error("Property 'x' is not initialized")

if (::y.isInitialized) throw Error("Property 'y' already initialized")
y = "Y"
if (!::y.isInitialized) throw Error("Property 'y' is not initialized")

return x + y
}

internal fun initializeAndReadXY(): String = doInitializeAndReadXY()

private inline fun doInitializeAndReadOK(): String {
if (::o.isInitialized) throw Error("Property 'o' already initialized")
o = "O"
if (!::o.isInitialized) throw Error("Property 'o' is not initialized")
Expand All @@ -14,7 +31,9 @@ class OK {

return o + k
}

internal inline fun initializeAndReadOK(): String = doInitializeAndReadOK()
}

// FILE: main.kt
fun box(): String = OK().initializeAndReadLateinitProperties()
fun box(): String = OK().initializeAndReadOK()
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@ public class OK
/* TARGET use-site */ <this>.#k
public fun <set-k>(<set-?>: String)
/* TARGET use-site */ <this>.#k = <set-?>
internal inline fun initializeAndReadLateinitProperties(): String
/* ACCESSOR use-site */ access$<get-o>$p($this = <this>)
/* ACCESSOR use-site */ access$<set-o>($this = <this>, <set-?> = "O")
/* ACCESSOR use-site */ access$<get-o>$p($this = <this>)
/* ACCESSOR use-site */ access$<get-k>$p($this = <this>)
/* ACCESSOR use-site */ access$<get-k>$p($this = <this>)
/* ACCESSOR use-site */ access$<get-o>($this = <this>)
private inline fun doInitializeAndReadOK(): String
/* TARGET use-site */ <this>.#o
/* TARGET use-site */ <this>.<set-o>(<set-?> = "O")
/* TARGET use-site */ <this>.#o
/* TARGET use-site */ <this>.#k
/* TARGET use-site */ <this>.#k
/* TARGET use-site */ <this>.<get-o>()
internal inline fun initializeAndReadOK(): String
/* ACCESSOR use-site */ access$<get-o>$p($this = this)
/* ACCESSOR use-site */ access$<set-o>($this = this, <set-?> = "O")
/* ACCESSOR use-site */ access$<get-o>$p($this = this)
/* ACCESSOR use-site */ access$<get-k>$p($this = this)
/* ACCESSOR use-site */ access$<get-k>$p($this = this)
/* ACCESSOR use-site */ access$<get-o>($this = this)
/* ACCESSOR declaration */ internal /* static */ fun access$<get-o>($this: OK): String
/* TARGET use-site */ $this.<get-o>()
/* ACCESSOR declaration */ internal /* static */ fun access$<set-o>($this: OK, <set-?>: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@ public class OK
/* TARGET use-site */ <this>.#k
public fun <set-k>(<set-?>: String)
/* TARGET use-site */ <this>.#k = <set-?>
internal inline fun initializeAndReadLateinitProperties(): String
/* ACCESSOR use-site */ access$<get-o>$p($this = <this>)
/* ACCESSOR use-site */ access$<set-o>($this = <this>, <set-?> = "O")
/* ACCESSOR use-site */ access$<get-o>$p($this = <this>)
/* ACCESSOR use-site */ access$<get-k>$p($this = <this>)
/* ACCESSOR use-site */ access$<get-k>$p($this = <this>)
/* ACCESSOR use-site */ access$<get-o>($this = <this>)
private inline fun doInitializeAndReadOK(): String
/* TARGET use-site */ <this>.#o
/* TARGET use-site */ <this>.<set-o>(<set-?> = "O")
/* TARGET use-site */ <this>.#o
/* TARGET use-site */ <this>.#k
/* TARGET use-site */ <this>.#k
/* TARGET use-site */ <this>.<get-o>()
internal inline fun initializeAndReadOK(): String
/* ACCESSOR use-site */ access$<get-o>$p($this = this)
/* ACCESSOR use-site */ access$<set-o>($this = this, <set-?> = "O")
/* ACCESSOR use-site */ access$<get-o>$p($this = this)
/* ACCESSOR use-site */ access$<get-k>$p($this = this)
/* ACCESSOR use-site */ access$<get-k>$p($this = this)
/* ACCESSOR use-site */ access$<get-o>($this = this)
/* ACCESSOR declaration */ public /* static */ fun access$<get-o>($this: OK): String
/* TARGET use-site */ $this.<get-o>()
/* ACCESSOR declaration */ public /* static */ fun access$<set-o>($this: OK, <set-?>: String)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
// MODULE: lib
// FILE: OK.kt
class OK {
private lateinit var x: String // never leaked
lateinit var y: String // never leaked

private lateinit var o: String
lateinit var k: String

internal inline fun initializeAndReadLateinitProperties(): String {
private inline fun doInitializeAndReadXY(): String {
if (::x.isInitialized) throw Error("Property 'x' already initialized")
x = "X"
if (!::x.isInitialized) throw Error("Property 'x' is not initialized")

if (::y.isInitialized) throw Error("Property 'y' already initialized")
y = "Y"
if (!::y.isInitialized) throw Error("Property 'y' is not initialized")

return x + y
}

internal fun initializeAndReadXY(): String = doInitializeAndReadXY()

private inline fun doInitializeAndReadOK(): String {
if (::o.isInitialized) throw Error("Property 'o' already initialized")
o = "O"
if (!::o.isInitialized) throw Error("Property 'o' is not initialized")
Expand All @@ -15,8 +32,10 @@ class OK {

return o + k
}

internal inline fun initializeAndReadOK(): String = doInitializeAndReadOK()
}

// MODULE: main()(lib)
// FILE: main.kt
fun box(): String = OK().initializeAndReadLateinitProperties()
fun box(): String = OK().initializeAndReadOK()
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@ public class OK
/* TARGET use-site */ <this>.#k
public fun <set-k>(<set-?>: String)
/* TARGET use-site */ <this>.#k = <set-?>
internal inline fun initializeAndReadLateinitProperties(): String
/* ACCESSOR use-site */ access$<get-o>$p($this = <this>)
/* ACCESSOR use-site */ access$<set-o>($this = <this>, <set-?> = "O")
/* ACCESSOR use-site */ access$<get-o>$p($this = <this>)
/* ACCESSOR use-site */ access$<get-k>$p($this = <this>)
/* ACCESSOR use-site */ access$<get-k>$p($this = <this>)
/* ACCESSOR use-site */ access$<get-o>($this = <this>)
private inline fun doInitializeAndReadOK(): String
/* TARGET use-site */ <this>.#o
/* TARGET use-site */ <this>.<set-o>(<set-?> = "O")
/* TARGET use-site */ <this>.#o
/* TARGET use-site */ <this>.#k
/* TARGET use-site */ <this>.#k
/* TARGET use-site */ <this>.<get-o>()
internal inline fun initializeAndReadOK(): String
/* ACCESSOR use-site */ access$<get-o>$p($this = this)
/* ACCESSOR use-site */ access$<set-o>($this = this, <set-?> = "O")
/* ACCESSOR use-site */ access$<get-o>$p($this = this)
/* ACCESSOR use-site */ access$<get-k>$p($this = this)
/* ACCESSOR use-site */ access$<get-k>$p($this = this)
/* ACCESSOR use-site */ access$<get-o>($this = this)
/* ACCESSOR declaration */ internal /* static */ fun access$<get-o>($this: OK): String
/* TARGET use-site */ $this.<get-o>()
/* ACCESSOR declaration */ internal /* static */ fun access$<set-o>($this: OK, <set-?>: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@ public class OK
/* TARGET use-site */ <this>.#k
public fun <set-k>(<set-?>: String)
/* TARGET use-site */ <this>.#k = <set-?>
internal inline fun initializeAndReadLateinitProperties(): String
/* ACCESSOR use-site */ access$<get-o>$p($this = <this>)
/* ACCESSOR use-site */ access$<set-o>($this = <this>, <set-?> = "O")
/* ACCESSOR use-site */ access$<get-o>$p($this = <this>)
/* ACCESSOR use-site */ access$<get-k>$p($this = <this>)
/* ACCESSOR use-site */ access$<get-k>$p($this = <this>)
/* ACCESSOR use-site */ access$<get-o>($this = <this>)
private inline fun doInitializeAndReadOK(): String
/* TARGET use-site */ <this>.#o
/* TARGET use-site */ <this>.<set-o>(<set-?> = "O")
/* TARGET use-site */ <this>.#o
/* TARGET use-site */ <this>.#k
/* TARGET use-site */ <this>.#k
/* TARGET use-site */ <this>.<get-o>()
internal inline fun initializeAndReadOK(): String
/* ACCESSOR use-site */ access$<get-o>$p($this = this)
/* ACCESSOR use-site */ access$<set-o>($this = this, <set-?> = "O")
/* ACCESSOR use-site */ access$<get-o>$p($this = this)
/* ACCESSOR use-site */ access$<get-k>$p($this = this)
/* ACCESSOR use-site */ access$<get-k>$p($this = this)
/* ACCESSOR use-site */ access$<get-o>($this = this)
/* ACCESSOR declaration */ public /* static */ fun access$<get-o>($this: OK): String
/* TARGET use-site */ $this.<get-o>()
/* ACCESSOR declaration */ public /* static */ fun access$<set-o>($this: OK, <set-?>: String)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
class OK {
private lateinit var x: String // never leaked
lateinit var y: String // never leaked

private lateinit var o: String
lateinit var k: String

internal inline fun initializeAndReadLateinitProperties(): String {
private inline fun doInitializeAndReadXY(): String {
if (::x.isInitialized) throw Error("Property 'x' already initialized")
x = "X"
if (!::x.isInitialized) throw Error("Property 'x' is not initialized")

if (::y.isInitialized) throw Error("Property 'y' already initialized")
y = "Y"
if (!::y.isInitialized) throw Error("Property 'y' is not initialized")

return x + y
}

internal fun initializeAndReadXY(): String = doInitializeAndReadXY()

private inline fun doInitializeAndReadOK(): String {
if (::o.isInitialized) throw Error("Property 'o' already initialized")
o = "O"
if (!::o.isInitialized) throw Error("Property 'o' is not initialized")
Expand All @@ -13,6 +30,8 @@ class OK {

return o + k
}

internal inline fun initializeAndReadOK(): String = doInitializeAndReadOK()
}

fun box(): String = OK().initializeAndReadLateinitProperties()
fun box(): String = OK().initializeAndReadOK()
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ public lateinit var k: String?
/* TARGET use-site */ #k
public fun <set-k>(<set-?>: String)
/* TARGET use-site */ #k = <set-?>
internal inline fun initializeAndReadLateinitProperties(): String
private inline fun doInitializeAndReadOK(): String
/* TARGET use-site */ #o
/* TARGET use-site */ <set-o>(<set-?> = "O")
/* TARGET use-site */ #o
/* TARGET use-site */ #k
/* TARGET use-site */ #k
/* TARGET use-site */ <get-o>()
internal inline fun initializeAndReadOK(): String
/* ACCESSOR use-site */ access$<get-o>$p$tOKKt()
/* ACCESSOR use-site */ access$<set-o>$tOKKt(<set-?> = "O")
/* ACCESSOR use-site */ access$<get-o>$p$tOKKt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ public lateinit var k: String?
/* TARGET use-site */ #k
public fun <set-k>(<set-?>: String)
/* TARGET use-site */ #k = <set-?>
internal inline fun initializeAndReadLateinitProperties(): String
private inline fun doInitializeAndReadOK(): String
/* TARGET use-site */ #o
/* TARGET use-site */ <set-o>(<set-?> = "O")
/* TARGET use-site */ #o
/* TARGET use-site */ #k
/* TARGET use-site */ #k
/* TARGET use-site */ <get-o>()
internal inline fun initializeAndReadOK(): String
/* ACCESSOR use-site */ access$<get-o>$p$tOKKt()
/* ACCESSOR use-site */ access$<set-o>$tOKKt(<set-?> = "O")
/* ACCESSOR use-site */ access$<get-o>$p$tOKKt()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
// FILE: OK.kt
private lateinit var x: String // never leaked
lateinit var y: String // never leaked

private lateinit var o: String
lateinit var k: String

internal inline fun initializeAndReadLateinitProperties(): String {
private inline fun doInitializeAndReadXY(): String {
if (::x.isInitialized) throw Error("Property 'x' already initialized")
x = "X"
if (!::x.isInitialized) throw Error("Property 'x' is not initialized")

if (::y.isInitialized) throw Error("Property 'y' already initialized")
y = "Y"
if (!::y.isInitialized) throw Error("Property 'y' is not initialized")

return x + y
}

internal fun initializeAndReadXY(): String = doInitializeAndReadXY()

private inline fun doInitializeAndReadOK(): String {
if (::o.isInitialized) throw Error("Property 'o' already initialized")
o = "O"
if (!::o.isInitialized) throw Error("Property 'o' is not initialized")
Expand All @@ -14,5 +31,7 @@ internal inline fun initializeAndReadLateinitProperties(): String {
return o + k
}

internal inline fun initializeAndReadOK(): String = doInitializeAndReadOK()

// FILE: main.kt
fun box(): String = initializeAndReadLateinitProperties()
fun box(): String = initializeAndReadOK()
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@

/* FILE package=<root> fileName=OK.kt */

internal inline fun initializeAndReadLateinitProperties(): String
internal inline fun initializeAndReadOK(): String
/* ACCESSOR use-site */ access$<get-o>$p$tOKKt()
/* ACCESSOR use-site */ access$<set-o>$tOKKt(<set-?> = "O")
/* ACCESSOR use-site */ access$<get-o>$p$tOKKt()
/* ACCESSOR use-site */ access$<get-k>$p$tOKKt()
/* ACCESSOR use-site */ access$<get-k>$p$tOKKt()
/* ACCESSOR use-site */ access$<get-o>$tOKKt()
private inline fun doInitializeAndReadOK(): String
/* TARGET use-site */ #o
/* TARGET use-site */ <set-o>(<set-?> = "O")
/* TARGET use-site */ #o
/* TARGET use-site */ #k
/* TARGET use-site */ #k
/* TARGET use-site */ <get-o>()
private lateinit var o: String?
/* TARGET declaration */ private /* static field */ field o: String?
/* TARGET declaration */ private fun <get-o>(): String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@

/* FILE package=<root> fileName=OK.kt */

internal inline fun initializeAndReadLateinitProperties(): String
internal inline fun initializeAndReadOK(): String
/* ACCESSOR use-site */ access$<get-o>$p$tOKKt()
/* ACCESSOR use-site */ access$<set-o>$tOKKt(<set-?> = "O")
/* ACCESSOR use-site */ access$<get-o>$p$tOKKt()
/* ACCESSOR use-site */ access$<get-k>$p$tOKKt()
/* ACCESSOR use-site */ access$<get-k>$p$tOKKt()
/* ACCESSOR use-site */ access$<get-o>$tOKKt()
private inline fun doInitializeAndReadOK(): String
/* TARGET use-site */ #o
/* TARGET use-site */ <set-o>(<set-?> = "O")
/* TARGET use-site */ #o
/* TARGET use-site */ #k
/* TARGET use-site */ #k
/* TARGET use-site */ <get-o>()
private lateinit var o: String?
/* TARGET declaration */ private /* static field */ field o: String?
/* TARGET declaration */ private fun <get-o>(): String
Expand Down
Loading

0 comments on commit fb4b1ad

Please sign in to comment.