-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add a deprecation notice about async constructors #4402
Conversation
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.
Please add a test in crates/macro/ui-tests
. We can take a second look at the wording then.
EDIT: A changelog entry is missing as well.
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.
Ah, unfortunately this doesn't seem to look right after all. Sorry!
The problem is we need a deprecation warning at the definition site, not the call site. Because realistically the call size will be in JS, not Rust.
This should work:
diff --git a/crates/backend/src/codegen.rs b/crates/backend/src/codegen.rs
index c8decb4a1..19bc75afd 100644
--- a/crates/backend/src/codegen.rs
+++ b/crates/backend/src/codegen.rs
@@ -806,6 +806,14 @@ impl TryToTokens for ast::Export {
add_check(quote! {
let _: #wasm_bindgen::__rt::marker::CheckSupportsConstructor<#class>;
});
+
+ if self.function.r#async {
+ (quote_spanned! {
+ self.function.name_span =>
+ let async_constructors_deprecated: ();
+ })
+ .to_tokens(into);
+ }
}
ast::MethodKind::Operation(operation) => match operation.kind {
ast::OperationKind::Getter(_) | ast::OperationKind::Setter(_) => {
I wanted to push this directly but didn't have permissions, but I can open a PR in your repo if this makes things easier.
@daxpedda I see, good point! But what do you think about still using the deprecated attribute? In my opinion, that outputs a better type of warning for this scenario than an unused variable. diff --git a/crates/backend/src/codegen.rs b/crates/backend/src/codegen.rs
index c8decb4a..e8ff0bcf 100644
--- a/crates/backend/src/codegen.rs
+++ b/crates/backend/src/codegen.rs
@@ -806,6 +806,16 @@ impl TryToTokens for ast::Export {
add_check(quote! {
let _: #wasm_bindgen::__rt::marker::CheckSupportsConstructor<#class>;
});
+
+ if self.function.r#async {
+ (quote_spanned! {
+ self.function.name_span =>
+ #[deprecated(note = "async constructors are not supported")]
+ fn constructor() {}
+ constructor();
+ })
+ .to_tokens(into);
+ }
}
ast::MethodKind::Operation(operation) => match operation.kind {
ast::OperationKind::Getter(_) | ast::OperationKind::Setter(_) => { |
Yes, definitely better! |
11a9293
to
b64aadb
Compare
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.
Apart from the outstanding issue it LGTM!
Thank you again!
df5a8bf
to
d0a68b6
Compare
Update tests to work with the new deprecation
d0a68b6
to
303fbf0
Compare
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.
Thank you!
Adds a deprecation attribute to the method marked as constructor if it is async.
Appreciate suggestions on wording in the deprecation notice.
Resolves #3976