feat: allow named parameters in mapping types

Co-authored-by: Hari <webmail.hari@gmail.com>

test: add parser and abi test cases

docs: add example on using named parameters for mappings

- Add changelog

feat: update antlr grammar to allow named parameters in mappings

fix: prevent conflicting mapping parameter names

ref: change order of mapping initializers

test: update expectations and fix build

test: add more tests

fix: use common error & code for conflicting params

fix: issue with accessing nested mapping

test: add conflicting params tests for more nested levels

Update libsolidity/analysis/DeclarationTypeChecker.cpp

Co-authored-by: Nikola Matić <nikola.matic@ethereum.org>

fix: error reported with the same code twice

test: add more tests for 3 level nested mapping

Address review comments
This commit is contained in:
Soham Zemse
2022-12-08 11:56:58 +01:00
committed by Nikola Matic
co-authored by Hari Nikola Matić
parent 1c8745c54a
commit fa78e0f3d4
75 changed files with 530 additions and 30 deletions
+6 -2
View File
@@ -1510,8 +1510,8 @@ private:
class MappingType: public CompositeType
{
public:
MappingType(Type const* _keyType, Type const* _valueType):
m_keyType(_keyType), m_valueType(_valueType) {}
MappingType(Type const* _keyType, ASTString _keyName, Type const* _valueType, ASTString _valueName):
m_keyType(_keyType), m_keyName(_keyName), m_valueType(_valueType), m_valueName(_valueName) {}
Category category() const override { return Category::Mapping; }
@@ -1531,14 +1531,18 @@ public:
std::vector<std::tuple<std::string, Type const*>> makeStackItems() const override;
Type const* keyType() const { return m_keyType; }
ASTString keyName() const { return m_keyName; }
Type const* valueType() const { return m_valueType; }
ASTString valueName() const { return m_valueName; }
protected:
std::vector<Type const*> decomposition() const override { return {m_valueType}; }
private:
Type const* m_keyType;
ASTString m_keyName;
Type const* m_valueType;
ASTString m_valueName;
};
/**