I built a composable function with the intent of r...
# compose
s
I built a composable function with the intent of reusing it in places in my app that want to show a Grid similar to the legacy android GridLayout. But compiling it gets this error with a long callstack:
Copy code
org.jetbrains.kotlin.backend.common.BackendException: Backend Internal error: Exception during IR lowering
File being compiled: <path>/GridDisplay.kt
The root cause java.lang.IllegalStateException was thrown at: org.jetbrains.kotlin.backend.common.lower.loops.RangeLoopTransformer.gatherLoopVariableInfo(ForLoopsLowering.kt:375)
Anyone else seen this? I started stripping stuff down and have a small function now that doesn't do much but builds fine, then a change to one line causes the build to fail with this error. I'll post the good code/failing code in a thread in case someone is interested. Weird. Searches show a similar error when trying to use kotlinx serialization and compose in the same module, but I don't have that scenario. My app does have three multi-platform modules using serialization, but the app module specific to android and using compose does not use serialization. Would this be a jetbrains defect or a Compose/google defect? Thanks in advance for any suggestions. FWIW this happens with kotlin 1.5.30 and compose 1.1.0-alpha04
Copy code
@Composable
fun GridDisplayTest(
) {
    Column(modifier = Modifier.fillMaxWidth()
    ) {
        var skip: Boolean
        for (rowIndex in 0 until 2) {
            skip = false
            Row(
                modifier = Modifier
                    .fillMaxWidth()
            ) {
                for (columnIndex in 0 until 4) {
                    if (skip) continue
                    val isLabel = columnIndex % 2 == 0
                    if (isLabel) {
                        Text("Any")
                    } else {
                        Text("Any2")
                    }
                }
            }
        }
    }
}
The above code build fails. If I change the one line (if/skip) line to the below, it builds fine:
Copy code
@Composable
fun GridDisplayTest(
) {
    Column(modifier = Modifier.fillMaxWidth()
    ) {
        var skip: Boolean
        for (rowIndex in 0 until 2) {
            skip = false
            Row(
                modifier = Modifier
                    .fillMaxWidth()
            ) {
                for (columnIndex in 0 until 4) {
                    if (!skip) {
                        val isLabel = columnIndex % 2 == 0
                        if (isLabel) {
                            Text("Any")
                        } else {
                            Text("Any2")
                        }
                    }
                }
            }
        }
    }
}
Something doesn't like the if/continue statement.
I did the same change (replace the if/continue) in the original full-function version and it builds fine.