kotlinpoet icon indicating copy to clipboard operation
kotlinpoet copied to clipboard

Get exception tying to generate empty fun interface which inherit another interface with exact one abstract function

Open jizoquval opened this issue 5 months ago • 3 comments

Describe the bug Using KotlinPoet 1.18.1 I get the exception: java.lang.IllegalStateException: Functional interfaces must have exactly one abstract function. Contained 0: [] when try to generate valid kotlin code. I'm trying to generate functional interface which doesn't contains new methods and inherits another functional interface with method declaration.

To Reproduce

    val bClassName = ClassName("","B")
    val aClassName = ClassName("","A")
    val fileSpec = FileSpec.builder("", "Example")
        .addType(
            TypeSpec.funInterfaceBuilder(bClassName)
                .addFunction(
                    FunSpec.builder("foo")
                        .addModifiers(KModifier.ABSTRACT)
                        .build(),
                )
                .build()
        )
        .addType(
            TypeSpec.funInterfaceBuilder(aClassName)
                .addSuperinterface(bClassName)
                .build()
        )
        .build()
    fileSpec.writeTo(System.out)

Expected behavior I expect to get generated code instead of exception.

Additional context This is a correct kotlin code and it can be compiled.

fun interface A: B

fun interface B {
  fun foo()
}

jizoquval avatar Aug 29 '24 10:08 jizoquval