Named arguments on inherited contracts

Hey team! Long-time Solidity engineer and first-time drafting a proposal to this awesome language so please forgive me if this post is disorganized.

Explanation

A feature of Solidity that I’ve grown to appreciate is the ability to pass in named arguments. Here’s a poor example:

function foo(uint256 a, uint256 b) private view returns (uint) {
    return a + b;
}

function bar(uint256 c, uint256 _a, uint256 _b) external view returns (uint) {
    ...
    return foo({b: _b, a: _a});
}

Not only has this helped prevent code flubs when re-ordering function arguments, but it also provides greater clarity to the reader on which arguments are passed where.

Unfortunately, this feature is unavailable when a contract is created who inherits another contract with constructor arguments. For example, this code:

contract MyToken is ERC20 {
    constructor(
        string memory name_, string memory symbol_
    ) ERC20({name_: name_, symbol_: symbol_}) {}
}

Fails with the following message:

Compiler run failed:
Error (6933): Expected primary expression.
  --> src/MyToken.sol:10:14:
   |
10 |     ) ERC20 ({name_: name_, symbol_: symbol_}) {}
   |              ^

I’ve reproduced this example with a minimal repository at:

Proposal

Allow named arguments to be passed into inherited contract constructors for improved contract security and readability.

2 Likes
  1. This question was already asked here about 6 months ago.
  2. This issue was already posted on github about 4 months ago.

As you can see in both of them, it applies not only to constructors, but also to modifiers.

2 Likes