aeternity / aesophia

Stand alone compiler for the Sophia smart contract language
https://docs.aeternity.com/aesophia
ISC License
51 stars 19 forks source link

False positive "is defined but never used" warning if event type in contract interface #491

Closed davidyuk closed 9 months ago

davidyuk commented 10 months ago

I found this behaviour in aesophia_cli, but probably it is related to the whole compiler.

Reproduction.aes

contract interface RemoteI =
  datatype event = RemoteEvent(int)
  entrypoint emitEvents : () => unit

contract Test =
  datatype event = Event(int)
  stateful entrypoint emitEvents(remote: RemoteI) : unit =
    Chain.event(Event(42))
    remote.emitEvents()
$ ./aesophia_cli --version                           
Sophia compiler version 7.4.0
$ ./aesophia_cli ./Reproduction.aes       
Warning in './Reproduction.aes' at line 2, col 3:
The type `event` is defined but never used.
cb_+OJGA6A8lEFdU+Y5bIcB/Y6CFyjQhDCni5at80+U1cCLiLmvDcC4tbiC/kTWRB8ANwA3ABoOgj8BAz/+ZaXgDwI3AYcBNwEHNwBGNgAAAGIvX58BgR9CGdutZoszd/R2GZyVS+3JJy1C+hSzitoW5feMmcSnAAEDP/7hKsRXADcBRwI3AAwDrwEAG1QCAxFlpeAPDwJvgibPDAMADAEAAwD8EeEqxFc3ADcAAK0vAxFE1kQfEWluaXQRZaXgDy1DaGFpbi5ldmVudBHhKsRXKWVtaXRFdmVudHOCLwCFNy40LjAAifgV3g==

I'm using this kind of contract to generate ACI. The event type provided in ACI is used to decode events emitted by emitEvents. I doubt that the compiler should warn about this.

ghallak commented 9 months ago

@davidyuk Why do you think this is a bug?

The warning is shown because neither the datatype event nor the data constructor RemoteEvent(int) are used.

ghallak commented 9 months ago

Closing this as it's the expected behavior and it's not a real bug.

davidyuk commented 9 months ago

So, compiler suggest me to remove event definition in RemoteI, but I need it in ACI to parse the emitted event on the aepp side (actually, it is implemented in sdk). Seems that there is no way to rewrite contact to fix warning and keep aepp working, can you confirm that?