compose-multiplatform icon indicating copy to clipboard operation
compose-multiplatform copied to clipboard

Qualified return with inline Compose makes it crash

Open Obdormio opened this issue 3 years ago • 3 comments

You can repro with something like this:

import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application

@Composable
inline fun MyBox(content: @Composable () -> Unit) {
    content()
}

@Composable
fun App(title: String) {
    MyBox {
        if (title == "A") {
            Text("is A")
            return@MyBox
        }

        Text("is not A")
    }
}

fun main() = application {
    Window(onCloseRequest = this::exitApplication) {
        App("A")
    }
}

and it crashes with something like this:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index -5 out of bounds for length 0
	at androidx.compose.runtime.SlotTableKt.key(SlotTable.kt:2570)
	at androidx.compose.runtime.SlotTableKt.access$key(SlotTable.kt:1)
	at androidx.compose.runtime.SlotReader.groupKey(SlotTable.kt:622)
	at androidx.compose.runtime.ComposerImpl.end(Composer.kt:1967)
	at androidx.compose.runtime.ComposerImpl.endGroup(Composer.kt:1323)
	at androidx.compose.runtime.ComposerImpl.endRoot(Composer.kt:1235)
	at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:2588)

Obdormio avatar Aug 06 '22 05:08 Obdormio

if (($dirty & 11 ^ 2) == 0 && $composer.getSkipping()) {
    $composer.skipToGroupEnd();
} else {
    int $changed$iv = 0;
    int $i$f$MyBox = false;
    $composer.startReplaceableGroup(-1976699843);
    ComposerKt.sourceInformation($composer, "C(MyBox)");
    int $changed = 14 & $changed$iv;
    int var8 = false;
    if (($changed & 11 ^ 2) == 0 && $composer.getSkipping()) {
        $composer.skipToGroupEnd();
    } else {
        $composer.startReplaceableGroup(537332467);
        if (Intrinsics.areEqual(title, "A")) {
            TextKt.Text-fLXpl1I("is A", (Modifier)null, 0L, 0L, (FontStyle)null, (FontWeight)null, (FontFamily)null, 0L, (TextDecoration)null, (TextAlign)null, 0L, 0, false, 0, (Function1)null, (TextStyle)null, $composer, 6, 0, 65534);
            $composer.endReplaceableGroup();
            $composer.endReplaceableGroup(); // TWO END_REPLACEABLE_GROUP HERE!!!
        } else {
            $composer.endReplaceableGroup();
            TextKt.Text-fLXpl1I("is not A", (Modifier)null, 0L, 0L, (FontStyle)null, (FontWeight)null, (FontFamily)null, 0L, (TextDecoration)null, (TextAlign)null, 0L, 0, false, 0, (Function1)null, (TextStyle)null, $composer, 6, 0, 65534);
        }
    }

    $composer.endReplaceableGroup();
}

Obdormio avatar Aug 06 '22 05:08 Obdormio

reproduced with 1.2.0-alpha01-dev778

eymar avatar Sep 08 '22 09:09 eymar

Could you please submit this issue into Google's issue tracker https://issuetracker.google.com/issues/new?component=612128 ?

eymar avatar Sep 08 '22 09:09 eymar

reproduced with 1.4.3

chizhanov avatar Oct 18 '23 15:10 chizhanov