Allow user-defined types as mapping keys in parser and restrict to contracts during type checking.

This commit is contained in:
Daniel Kirchner
2020-02-04 17:22:03 +01:00
parent 7a194ffdab
commit d3cbfb0c5c
25 changed files with 808 additions and 18 deletions
+19
View File
@@ -2876,6 +2876,25 @@ void TypeChecker::endVisit(Literal const& _literal)
_literal.annotation().isPure = true;
}
bool TypeChecker::visit(Mapping const& _mapping)
{
if (auto const* keyType = dynamic_cast<UserDefinedTypeName const*>(&_mapping.keyType()))
{
if (
keyType->annotation().type->category() != Type::Category::Contract &&
keyType->annotation().type->category() != Type::Category::Enum
)
m_errorReporter.typeError(
keyType->location(),
"Only elementary types, contract types or enums are allowed as mapping keys."
);
}
else
solAssert(dynamic_cast<ElementaryTypeName const*>(&_mapping.keyType()), "");
return true;
}
bool TypeChecker::contractDependenciesAreCyclic(
ContractDefinition const& _contract,
std::set<ContractDefinition const*> const& _seenContracts