I think I might have found a bug in the Compose co...
# compose
t
I think I might have found a bug in the Compose compiler. If you have an interface that defines Composable functions, you cannot use default values without it crashing. I’ll put full code examples in the thread
Copy code
interface Foo {
    //This will crash if overridden and called with the default value
    @Composable
    fun Bar(modifier: Modifier = Modifier) {
    }
}
Impl
Copy code
class FooBar : Foo {
    @Composable
    override fun Bar(modifier: Modifier) {
        println("$modifier")
    }
}


interface Foo {
    //This will crash if overridden and called with the default value
    @Composable
    fun Bar(modifier: Modifier = Modifier) {
    }
}
Crash is:
Copy code
java.lang.NullPointerException: Parameter specified as non-null is null: method com.example.myapplication.FooBar.Bar, parameter modifier
                                                                                                    	at com.example.myapplication.FooBar.Bar(Unknown Source:2)
Copy code
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val fooBar = FooBar()
        setContent {
            fooBar.Bar()
        }
    }
}
How it’s called
If I make them not Composable functions it works without crashing
j
File a bug. The compiler should never crash.
t
This does crash at runtime and not compile-time
b
Definitely a compiler bug, can you please file an issue? https://goo.gle/compose-feedback
I should add as well, default values in composable interface functions are currently not supported. The compiler should be picking that up at compile time though, not runtime.
1
t