ink icon indicating copy to clipboard operation
ink copied to clipboard

In cross-call contract, ink! cannot pass compile for the parent contract contains event

Open atenjin opened this issue 3 years ago • 4 comments

Questions It's a bug in ink!, it may appear after pr https://github.com/paritytech/ink/pull/665

FAQ

ink! version: e8d4739649293a458c3958bec802d2d750067d98 cargo-contract version: cargo-contract 0.15.0-unknown-x86_64-linux-gnu

Describe the bug example repo: https://github.com/atenjin/ink-event-bug

in this repo, test2 contract crate depends on test contract crate. So the contract Test2 in test2 will use the TestRef from the contract Test in test.

and in test/lib.rs:L20, I add a event definition, and do nothing.

    #[ink(event)]
    pub struct OtherThing;

and in test2/lib.rs:L23, I aslo define a event:

    #[ink(event)]
    pub struct Tmp;

and emit this event in following code, line 50

self.env().emit_event(Tmp {});

then in test2 directory, execute compile command, it cannot pass compile for the following error:

error[E0284]: type annotations needed
  --> /home/king/workspace/patractlabs/contracts/tmp/test2/lib.rs:50:24
   |
50 |             self.env().emit_event(Tmp {});
   |                        ^^^^^^^^^^ cannot infer type for type parameter `C` declared on the trait `EmitEvent`
   |
   = note: cannot satisfy `<_ as ContractEventBase>::Type == _`

if remove the emit_event, then Test2 can pass the compilation. But we need the event.

And If I remove the event definition in Test, then compiling Test2 can work normally.

and other people so in element, if I change the emit_event like this, can pass the compilation.

            // self.env().emit_event(Tmp {});
            ink_lang::codegen::EmitEvent::<Test2>::emit_event(self.env(), Tmp {});

Obviously, the type inference is broken when Test2 use the contract TestRef.

I think it can be fixed just changing some small part, right? @Robbepop

atenjin avatar Nov 02 '21 12:11 atenjin

Same issue.

DukeCaesar avatar May 12 '22 02:05 DukeCaesar

@ascjones Do you have an idea if this will be fixed with https://github.com/paritytech/ink/pull/1243 ?

cmichi avatar May 12 '22 04:05 cmichi

Yes it will

ascjones avatar May 12 '22 11:05 ascjones