Disallow libraries as mapping keys.

This commit is contained in:
Daniel Kirchner
2020-02-06 09:09:43 +01:00
parent dd7a5c3386
commit e07274a96f
6 changed files with 13 additions and 4 deletions
+9 -4
View File
@@ -2880,10 +2880,15 @@ 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
)
if (auto const* contractType = dynamic_cast<ContractType const*>(keyType->annotation().type))
{
if (contractType->contractDefinition().isLibrary())
m_errorReporter.typeError(
keyType->location(),
"Library types cannot be used as mapping keys."
);
}
else if (keyType->annotation().type->category() != Type::Category::Enum)
m_errorReporter.typeError(
keyType->location(),
"Only elementary types, contract types or enums are allowed as mapping keys."