aeternity / aesophia

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

Allow interfaces with defined state type #507

Open ghallak opened 7 months ago

ghallak commented 7 months ago

This PR fixes the issue that prevents the compilation of contract interfaces in which state type is defined. Example:

contract interface I =
  record state = { x : int }
  entrypoint f : () => state
  entrypoint init : () => state

main contract C =
  entrypoint g(c : I) : int = c.f().x
ghallak commented 7 months ago

@hanssv Do you think that the following contract should compile? Should init only be required only when clone is called on the contract interface or should it be required for all contract interfaces where state is not unit?

contract interface I =
  record state = { x : int }
  entrypoint f : () => state

main contract C =
  entrypoint g(c : I) : int = c.f().x
hanssv commented 7 months ago

@hanssv Do you think that the following contract should compile? Should init only be required only when clone is called on the contract interface or should it be required for all contract interfaces where state is not unit?

contract interface I =
  record state = { x : int }
  entrypoint f : () => state

main contract C =
  entrypoint g(c : I) : int = c.f().x

In general the interfaces only need to contain what is used in the main contract, so in that spirit I think it should compile, yes. But it wouldn't be the end of the world if it doesn't. But let's see if we can collect a few more opinions.

radrow commented 7 months ago

Right now we have a special void type for cases where we don't really care what a thing is, but we want to make it unusable (like in the case of init in interfaces). I think we should stick to that and even more - enforce interface init to return void, since we have no way to check what is the type of the contract's actual state.

hanssv commented 7 months ago

But for clone the type is needed, right? But since that is the only case where init is "useable" that could be the only place we require to list init?!

radrow commented 7 months ago

For clone you only need arguments. The return type should remain opaque, however. I am thinking of making it either some explicitly "unknown" type such as void or ???, or some hardcoded (and equally unusable) NameOfTheInterface.state