-
Notifications
You must be signed in to change notification settings - Fork 22
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
Fix several issues dealing with the error interface #48
Conversation
31db216
to
fda6ef5
Compare
Hi! I thought of a bit different approach. This also uses pointers always. But instead of casting do all the changes during code generation. The tests from #36 and #47 pass. What do you think? Could be applied on 62738f9
|
This looks good on my end, the project I work with compiles fine with your diff. It's a better solution as it doesn't rely on runtime type assertions :D |
I think neither of these approaches address the underlying problems, enum/error types are ambiguous. While this PR fixes referencing errors inside an error (nested error), it does not fixed the issue of referencing error type in other declarations, i.e. function arguments, structs, associated enums. A dictionary that references an enum still generates invalid code. If this PR fixes your immediate use case, I don't see a problem with merging it. I would prefer to have the compile time solution proposed by @Savolro, but I think even the runtime solution is fine for the time being, until the underlying issue can be addressed. diff --git a/fixtures/errors/src/errors.udl b/fixtures/errors/src/errors.udl
index d1dda93..0a6a709 100644
--- a/fixtures/errors/src/errors.udl
+++ b/fixtures/errors/src/errors.udl
@@ -19,6 +19,10 @@ enum BoobyTrapError {
"HotDoorKnob",
};
+dictionary StructWithError {
+ ValidationError e;
+};
+
[Error]
interface NestedError {
Nested(ValidationError source);
diff --git a/fixtures/errors/src/lib.rs b/fixtures/errors/src/lib.rs
index 4c51ea4..11772b0 100644
--- a/fixtures/errors/src/lib.rs
+++ b/fixtures/errors/src/lib.rs
@@ -4,6 +4,10 @@
use std::collections::HashMap;
+struct StructWithError {
+ e: ValidationError,
+}
+
#[derive(Debug, thiserror::Error)]
pub enum BoobyTrapError {
#[error("You slipped on deliberately poured ice")]
|
It does solve my immediate problem, so it would be helpful to land @Savolro's patch. |
Can you apply his changes in this PR? |
fd9ee4a
to
39f4348
Compare
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 <[email protected]>
39f4348
to
6206a6f
Compare
Done. |
Is tihs a breaking change for anyone using the current main bindings? If they update to this version, will they have to update their code to make it work with these changes? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
This PR fixes 2 issues:
Both have tests added.
There's two main changes to fix these issues:
error
interface and need to type cast to.(*LiteralError)
. This PR does this in tactical places to prevent compile errors. Tests should confirm that these type assertions are safe.