Merge pull request #8254 from ethereum/librariesAsMappingKeys

Disallow libraries as mapping keys.
This commit is contained in:
chriseth 2020-02-06 09:45:51 +01:00 committed by GitHub
commit 93191cebee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 4 deletions

View File

@ -2880,10 +2880,15 @@ bool TypeChecker::visit(Mapping const& _mapping)
{ {
if (auto const* keyType = dynamic_cast<UserDefinedTypeName const*>(&_mapping.keyType())) if (auto const* keyType = dynamic_cast<UserDefinedTypeName const*>(&_mapping.keyType()))
{ {
if ( if (auto const* contractType = dynamic_cast<ContractType const*>(keyType->annotation().type))
keyType->annotation().type->category() != Type::Category::Contract && {
keyType->annotation().type->category() != Type::Category::Enum 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( m_errorReporter.typeError(
keyType->location(), keyType->location(),
"Only elementary types, contract types or enums are allowed as mapping keys." "Only elementary types, contract types or enums are allowed as mapping keys."

View File

@ -0,0 +1,4 @@
library L {}
contract C { mapping(L => bool) i; }
// ----
// TypeError: (34-35): Library types cannot be used as mapping keys.