Skip to content
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

Self shouldn't be concretized on traits #1200

Open
mitinarseny opened this issue Jun 12, 2024 · 2 comments
Open

Self shouldn't be concretized on traits #1200

mitinarseny opened this issue Jun 12, 2024 · 2 comments

Comments

@mitinarseny
Copy link
Contributor

Hey Team,

The #1001 fix makes it impossible to define a trait with #[init] method that returns Self:

#[ext_contract(ext_my_contract)]
pub trait MyContract {
    #[init]
    fn new() -> Self;
}

as it expands into

pub trait MyContract {
    fn new() -> MyContract;
}

pub mod ext_my_contract {
    // ...
}

And results into following error:

error[E0782]: trait objects must include the `dyn` keyword
 --> src/lib.rs:2:16:
  |
6 |     fn new() -> Self;
  |                 ^^^^
  |
help: add `dyn` keyword before this trait
  |
6 |     fn new() -> dyn Self;
  |                 +++
@frol
Copy link
Collaborator

frol commented Jun 21, 2024

@mitinarseny I think there is no meaning for #[init] in the traits. Does it work if you don't put #[init] there?

@mitinarseny
Copy link
Contributor Author

mitinarseny commented Jul 8, 2024

Does it work if you don't put #[init] there?

Apparently, #[near] requires #[init] on all methods returning Self. Constructors usually do that

I think there is no meaning for #[init] in the traits

I respectfully disagree as it can be helpful if you want to write a Deployer contract which would be responsible for deploying other contracts, so one can use bindings for constructors of these contracts as well.

With that being said, it still wouldn't let you to write a Deployer contract that would deploy another contract and call #[init] method on it, as the current implementation of #[ext_contract] generates the code that creates Promise internally and doesn't let you to insert any other actions (such as .deploy(wasm)) prior to the function call itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: NEW❗
Development

No branches or pull requests

2 participants