argotorg / argotorg/solidity

Introduce a type definition keyword

Open
#1,100 14 comments 18 reactions 0 assignees View on GitHub
language design :rage4: low effort medium impact must have eventually
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
1d 11h
Merged PRs (30d)
21

Description

Solidity has `struct` by which arbitrary complex data structures can be created and referenced through named members. I find struct's, as a type, are particularly handy when coupled with a library through the `using X for Y` convention. But for some complex types names aren't necessarily needed but they can't be passed to functions and libraries (or I don't know how) without a `struct` wrapper....

``` javascript
library LibFoo {
struct MyUneccessaryStruct {
mapping (uint => mapping (uint => string)) IWishIDidnotHaveToDereferenceThisNameEveryTime
}

function libFunc(MyStruct self, uint a, uint b) internal {
return self.IWishIDidnotHaveToDereferenceThisNameEveryTime[a][b];
}
}

contract Foo {
using LibFoo for LibFoo.MyUneccessaryStruct;
LibFoo.MyUneccessaryStruct bar;
function foobar(uint a, uint b, string message) returns (string) {
bar.IWishIDidnotHaveToDereferenceThisNameEveryTime[a][b] = message;
return bar.libFunc(a,b);
}
```

What I would like to see is a type definition keyword (`typedef`) to simplify and enhance the usability of complex types in the following sense...

```
library LibFoo {
typedef mapping (uint => mapping (uint => string)) MyComplexType;

function libFunc(MyComplexType storage self, uint a, uint b) internal returns (string) {
return self[a][b];
}
}

contract Foo {
using LibFoo for LibFoo.MyComplexType;
LibFoo.MyComplexType bar;
function foobar(uint a, uint b, string message) returns (string) {
bar[a][b] = message;
return bar.libFunc(a,b);
}
}
```

Contributor guide

Open the contributing guide

Research direction

The issue contains no repository files, tests, or entry points to begin from. Start by reviewing the proposed typedef syntax and its interaction with mappings, storage parameters, libraries, and using directives; done would require an agreed language design and corresponding compiler coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
solidity
Domain
blockchain, compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.