uniffi-rs
uniffi-rs copied to clipboard
Kotlin: enum variants names can not be the same as a type name
eg, if you change https://github.com/mozilla/uniffi-rs/blob/7c5796b99d88aae567a8291b0bf8fb8f203f1e6c/fixtures/coverall/src/lib.rs#L121-L123 like:
diff --git a/fixtures/coverall/src/lib.rs b/fixtures/coverall/src/lib.rs
index ae43a7361..994568960 100644
--- a/fixtures/coverall/src/lib.rs
+++ b/fixtures/coverall/src/lib.rs
@@ -120,7 +120,7 @@ pub enum RootError {
#[error(transparent)]
// XXX - note Kotlin fails if this variant was called ComplexError
// (ie, the variant name can't match an existing type)
- Complex {
+ ComplexError {
#[from]
error: ComplexError,
},
@@ -131,7 +131,7 @@ pub enum RootError {
// For Kotlin, we throw a variant which itself is a plain enum.
#[uniffi::export]
fn throw_root_error() -> Result<(), RootError> {
- Err(RootError::Complex {
+ Err(RootError::ComplexError {
error: ComplexError::OsError {
code: 1,
extended_code: 2,
Kotlin will fail to compile the generated code:
.../src/moz/uniffi-rs/target/tmp/uniffi-fixture-coverall-8834fc094cadaaf3/uniffi/coverall/coverall.kt:3855:17: error: type mismatch: inferred type is uniffi.coverall.ComplexException but uniffi.coverall.RootException.ComplexException was expected
FfiConverterTypeComplexError.read(buf),
^
.../src/moz/uniffi-rs/target/tmp/uniffi-fixture-coverall-8834fc094cadaaf3/uniffi/coverall/coverall.kt:3869:63: error: type mismatch: inferred type is uniffi.coverall.RootException.ComplexException but uniffi.coverall.ComplexException was expected
+ FfiConverterTypeComplexError.allocationSize(value.`error`)
^
The solution seems to be that we must somehow specify the fully-qualified name of the "outer" type when generating the enum body.