Skip to content

Commit

Permalink
IR: Lower shared variables in enum entries (KT-46605)
Browse files Browse the repository at this point in the history
(cherry picked from commit 60bc0f4)
  • Loading branch information
Steven Schäfer authored and Space committed May 19, 2021
1 parent 43a81e3 commit 87b2cc1
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 4 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ val sharedVariablesPhase = makeIrFilePhase(
class SharedVariablesLowering(val context: BackendContext) : BodyLoweringPass {

override fun lower(irBody: IrBody, container: IrDeclaration) {
// TODO remove this condition
if (container is IrFunction || container is IrField || container is IrAnonymousInitializer) {
SharedVariablesTransformer(irBody, container).lowerSharedVariables()
}
SharedVariablesTransformer(irBody, container).lowerSharedVariables()
}

private inner class SharedVariablesTransformer(val irBody: IrBody, val irDeclaration: IrDeclaration) {
Expand Down
17 changes: 17 additions & 0 deletions compiler/testData/codegen/box/enum/kt46605.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
fun call(f: () -> Unit) {
f()
}

enum class E(val f: () -> String) {
A({
var value = "Fail"
call {
value = "OK"
}
value
})
}

fun box(): String {
return E.A.f()
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 87b2cc1

Please sign in to comment.