Android Studioにて、変更をコミットしたらName shadowed: ...
と表示された。
Warning:(26, 94) Name shadowed: content
該当のコードは次のようなコードだった。
@Composable
fun ExampleComposable(
...
background: @Composable (route: String?, content: @Composable () -> Unit) -> Unit = { _, content -> content() },
content: @Composable (
...
) -> Unit,
) {
...
}
原因は、ExampleComposable()
に渡されるcontent
という引数名と、もう一つの引数のbackground()
の中で使われているcontent
が同じ名前だったことが原因だった。
そもそもShadowed
とは、内側のスコープにある変数やシンボルが外側のスコープにある変数やシンボルを隠してしまうことを意味している。
この場合、background()
の中で使われているcontent
が外側のスコープにあるcontent
を隠してしまっているので、Name shadowed
という警告が出ていたようだ。
なので、background()
の中で使われているcontent
をbackgroundContent
という名前に変更することで、警告が消えた。
@Composable
fun ExampleComposable(
...
background: @Composable (route: String?, backgroundContent: @Composable () -> Unit) -> Unit = { _, backgroundContent -> backgroundContent() },
content: @Composable (
...
) -> Unit,
) {
...
}