-
Notifications
You must be signed in to change notification settings - Fork 105
Copy trait docs to overridden functions without docs #1760
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
base: main
Are you sure you want to change the base?
Changes from all commits
f7c4477
5b48409
b6ecbea
aecbe73
724e6c5
ec29c6c
e40ea24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -269,12 +269,24 @@ pub fn contractimpl(metadata: TokenStream, input: TokenStream) -> TokenStream { | |
|
|
||
| match derived { | ||
| Ok(derived_ok) => { | ||
| let mut output = quote! { | ||
| #[#crate_path::contractargs(name = #args_ident, impl_only = true)] | ||
| #[#crate_path::contractclient(crate_path = #crate_path_str, name = #client_ident, impl_only = true)] | ||
| #[#crate_path::contractspecfn(name = #ty_str)] | ||
| #imp | ||
| #derived_ok | ||
| // When contracttrait is true, spec generation for overridden | ||
| // functions is handled by the macro bridge (so that trait docs can | ||
| // be used as fallback), so contractspecfn is not applied here. | ||
|
Comment on lines
+272
to
+274
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this breaks associated type resolution for overridden functions, as we skip the code path that does Consider: #[contract]
pub struct Contract;
#[contracttrait]
pub trait Trait {
type Value;
fn echo_value(value: u64) -> u64 {
value
}
}
#[contractimpl(contracttrait)]
impl Trait for Contract {
type Value = u64;
fn echo_value(value: Self::Value) -> Self::Value {
value + 1
}
}The resulting interface is: |
||
| let mut output = if args.contracttrait { | ||
| quote! { | ||
| #[#crate_path::contractargs(name = #args_ident, impl_only = true)] | ||
| #[#crate_path::contractclient(crate_path = #crate_path_str, name = #client_ident, impl_only = true)] | ||
| #imp | ||
|
Comment on lines
+272
to
+279
|
||
| #derived_ok | ||
| } | ||
| } else { | ||
| quote! { | ||
| #[#crate_path::contractargs(name = #args_ident, impl_only = true)] | ||
| #[#crate_path::contractclient(crate_path = #crate_path_str, name = #client_ident, impl_only = true)] | ||
| #[#crate_path::contractspecfn(name = #ty_str)] | ||
| #imp | ||
| #derived_ok | ||
| } | ||
| }; | ||
|
|
||
| // See soroban-sdk/docs/contracttrait.md for documentation on how | ||
|
|
||
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.
I believe this adds an edge case where a trait override functions can't be cfg gated:
Consider:
You would expect that this compiles, and either overrides the default trait function with the cfg condition is true, or uses the trait default if false.
I don't think this strictly is a blocker. Trait override functions have some existing edge cases with cfg flags that need to get worked out, so am OK pushing this to a separate issue.