Skip to content

Allow interfaces with defined state type#507

Open
ghallak wants to merge 1 commit intomasterfrom
ghallak/interface-init
Open

Allow interfaces with defined state type#507
ghallak wants to merge 1 commit intomasterfrom
ghallak/interface-init

Conversation

@ghallak
Copy link
Member

@ghallak ghallak commented Apr 29, 2024

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
Copy link
Member Author

ghallak commented Apr 29, 2024

@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
Copy link
Member

hanssv commented Apr 29, 2024

@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
Copy link
Member

radrow commented Apr 29, 2024

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
Copy link
Member

hanssv commented May 2, 2024

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
Copy link
Member

radrow commented May 2, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants