Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composable throws "kotlin.NotImplementedError: An operation is not implemented: Unknown file" compile error

I wish to have an interface which has a composable function Show like this in Android project feature module A.

interface AInterface {
    @Composable
    fun Show(modifier: Modifier = Modifier)
}

class AInterfaceImpl : AInterface {
    @Composable
    override fun Show(modifier: Modifier) {
        Text(
            modifier = modifier,
            text = "Message",
        )
    }
}

And inject the AInterfaceImpl object to Android project feature module B using Hilt and when I call aInterfaceImpl.Show(modifier) in Composable function from module B, it throws the below compile error.

@Composable
fun ShowAInterfaceImpl(
    modifier: Modifier,
    aInterface: AInterface
) {
    aInterface.Show(
        modifier = modifier
    )

}
kotlin.NotImplementedError: An operation is not implemented: Unknown file
    at org.jetbrains.kotlin.ir.util.IrUtilsKt.getFile(IrUtils.kt:634)
    at androidx.compose.compiler.plugins.kotlin.lower.InferenceFunctionDeclaration.toScheme(ComposableTargetAnnotationsTransformer.kt:680)
    at androidx.compose.compiler.plugins.kotlin.lower.InferenceFunctionDeclaration.toDeclaredScheme(ComposableTargetAnnotationsTransformer.kt:671)
    at androidx.compose.compiler.plugins.kotlin.lower.InferenceFunction.toDeclaredScheme$default(ComposableTargetAnnotationsTransformer.kt:614)

I spent a lot of time working around it, however, I have not got any clue. If anyone has any clue, please let me know. Thanks in advance.

like image 975
mooongcle Avatar asked Oct 30 '25 02:10

mooongcle


1 Answers

I have investigated this issue for a long time and found the below two issues:

  • https://issuetracker.google.com/issues/317490247
  • https://issuetracker.google.com/issues/165812010

So basically, Composable function in the interface does not support the function parameter default value.

interface AInterface {
    @Composable
    fun Show(modifier: Modifier)
}

So it works. Thanks.

like image 69
mooongcle Avatar answered Nov 01 '25 18:11

mooongcle