-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generated code requires unknownFields
named param when called from Swift
#225
Comments
This issue is a result of Kotlin/Native's interop happening through Objective-C. Objective-C does not support default argument values, whereas Swift does. Kotlin/Native may eventually support Swift directly but work is not currently happening on it. The way to solve this via Objective-C is to declare multiple methods that pass default values as necessary. We can achieve this result via Kotlin/Native by using a secondary constructor that provides the appropriate default value for For the example above, the generator should produce the additional @pbandk.Export
public data class IdRequest(
val id: String = "",
override val unknownFields: Map<Int, pbandk.UnknownField> = emptyMap()
) : pbandk.Message {
constructor(id: String) : this(id, emptyMap<Int, pbandk.UnknownField>())
// ... This allows the Swift code to omit To be clear, this is a Kotlin/Native issue. But, for the time being, it would be nice if pbandk can provide the secondary constructor workaround to make Swift interop more pleasant. |
Thanks for the investigation @darronschall! A couple thoughts on this:
|
I'm experimenting with a Kotlin/Native KMM project that uses
pbandk
to generate code from a.proto
file. I'm using KMM to share the network integration layer between iOS and Android apps.Currently, the generated code provides a default value for
unknownFields
allowing the parameter to be omitted from the constructor in Kotlin code. This does not bridge into Swift properly, forcing the call site to always specify a value for the parameter.For example, this message in the .proto file:
Will generate this data class via pbandk (0.14.1):
When I use this class from Android, I'm able to properly omit
unknownFields
from the call site:... but, when I call this from iOS via Swift, I have to explicitly pass the argument, otherwise I'm met with a Swift compiler error:
Missing argument for parameter 'unknownFields' in call
:Ideally, the pbandk generated code would allow the Swift call-site to omit
unknownFields
as well.The text was updated successfully, but these errors were encountered: