https://kotlinlang.org logo
#compose
Title
# compose
y

Yang

12/15/2019, 5:04 AM
Not sure if it's related to the compiler plugin but is there a known issue with the IR compiler where a Java SAM within a suspend function fails to compile? Java interface:
Copy code
public interface JavaInterface {
    // this only happens when the method returns void
    void test();
}
Copy code
class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        GlobalScope.launch {
            test()
        }
    }
}

suspend fun test() {
    withContext(Dispatchers.Default) {
        // sam conversion won't compile
        val listener1 = JavaInterface {
            println("")
        }

        // this works
        val listener2 = object : JavaInterface {
            override fun test() {
                println("")
            }
        }
    }
}
i

itnoles

12/15/2019, 7:17 AM
I think you are in the wrong channels
l

Leland Richardson [G]

12/15/2019, 5:38 PM
it is a known issue. suspend functions are not fully supported in the IR backend yet.
y

Yang

12/15/2019, 11:52 PM
Thanks @Leland Richardson [G] !
2 Views