-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Error as callback parameter does not compile #36
Comments
I think I have a failing test case for this in kegsay/uniffi-bindgen-go@main...kegsay:uniffi-bindgen-go:kegan/nested-error - build.sh and build_bindings.sh work fine but on test_bindings:
I think the right solution is to take a pointer to Specifically, taking a pointer to // Variant structs
type NestedErrorNested struct {
Source ValidationError // <-- *ValidationError
}
func NewNestedErrorNested(
source ValidationError, // <-- *ValidationError
) *NestedError {
return &NestedError{
err: &NestedErrorNested{
Source: source,
},
}
} at which point the only compilation failure is in: return &NestedError{&NestedErrorNested{
Source: FfiConverterTypeValidationErrorINSTANCE.Read(reader),
}} because Doing both of these things causes the tests to pass. |
@Savolro maybe you want to take a look at this one? I think you are the one who last touched errors as concrete types for callbacks, instead of |
Should fix NordSecurity#36 Definitely fixes an issue I've been having where the given test case fails with: ``` generated/errors/errors.go:1399:12: cannot use FfiConverterTypeValidationErrorINSTANCE.Read(reader) (value of type error) as ValidationError value in struct literal: need type assertion generated/errors/errors.go:1410:57: cannot use variantValue.Source (variable of type ValidationError) as *ValidationError value in argument to FfiConverterTypeValidationErrorINSTANCE.Write ``` This seems to be because the code sometimes expected `*ValidationError` and sometimes `ValidationError`. This patch makes the code use `*ValidationError` everywhere. Tests should hopefully prove they don't nil deference.
Should fix NordSecurity#36 Definitely fixes an issue I've been having where the given test case fails with: ``` generated/errors/errors.go:1399:12: cannot use FfiConverterTypeValidationErrorINSTANCE.Read(reader) (value of type error) as ValidationError value in struct literal: need type assertion generated/errors/errors.go:1410:57: cannot use variantValue.Source (variable of type ValidationError) as *ValidationError value in argument to FfiConverterTypeValidationErrorINSTANCE.Write ``` This seems to be because the code sometimes expected `*ValidationError` and sometimes `ValidationError`. This patch makes the code use `*ValidationError` everywhere. Tests should hopefully prove they don't nil deference. Signed-off-by: Kegan Dougal <7190048+kegsay@users.noreply.github.com>
Produces code like this: ``` func (foreignCallbackCallbackInterfaceCallback) InvokeDoSomething(callback Callback, args []byte, outBuf *C.RustBuffer) uniffiCallbackResult { reader := bytes.NewReader(args) callback.DoSomething(FfiConverterTypeBoobyTrapErrorINSTANCE.Read(reader).(*BoobyTrapError)) return uniffiCallbackResultSuccess } func (foreignCallbackCallbackInterfaceCallback) InvokeDoSomethingElse(callback Callback, args []byte, outBuf *C.RustBuffer) uniffiCallbackResult { reader := bytes.NewReader(args) callback.DoSomethingElse(FfiConverterTypeSomeEnumINSTANCE.Read(reader)) return uniffiCallbackResultSuccess } ``` Note the type-cast on `Read(reader)` for errors. Signed-off-by: Kegan Dougal <7190048+kegsay@users.noreply.github.com>
Generate pointers to structs consistently, rather than using the `error` interface in places. This fixes two issues: - fix an issue where nested variants did not work correctly when the nested variant was an error. - fix an issue where a callback could not be used with an error (NordSecurity#36)
Generate pointers to structs consistently, rather than using the `error` interface in places. This fixes two issues: - fix an issue where nested variants did not work correctly when the nested variant was an error. - fix an issue where a callback could not be used with an error (NordSecurity#36) Signed-off-by: Kegan Dougal <7190048+kegsay@users.noreply.github.com>
Generate pointers to structs consistently, rather than using the `error` interface in places. This fixes two issues: - fix an issue where nested variants did not work correctly when the nested variant was an error. - fix an issue where a callback could not be used with an error (#36) Signed-off-by: Kegan Dougal <7190048+kegsay@users.noreply.github.com>
This can be closed now. |
Compilation error in generated bindings:
Steps to repro in tests (0.2.0+v0.25.0):
Source: #35
The text was updated successfully, but these errors were encountered: