Allow type inference for Contracts and (some) Structs

First, this is ambiguous:

_contract = new MyContract();

Currently this is valid code if _contract has already been declared because = can be used in in expressions.

Also, I think that it reduces readability. Now you cannot be sure whether it’s a declaration of a new variable or an assignment without knowing the context.

I think it’s less error-prone when declarations have a dedicated syntax. For the compiler to distinguish them, we’d need for example a keyword that introduces a declaration:

var _contract = new MyContract();

which, incidentally, used to be a feature of the compiler but was removed long ago. Do we want var back? :slight_smile:

Second, I really liked the idea of inline structs, which would already allow initializing them in a DRY way:

MyStruct memory B = {bar: "baz"};

Do we really want to have yet another way to do this? Solidity has a lot of influences from C++ but having a million ways to initialize stuff fortunately wasn’t one of them so far :stuck_out_tongue:

1 Like