mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #8254 from ethereum/librariesAsMappingKeys
Disallow libraries as mapping keys.
This commit is contained in:
commit
93191cebee
@ -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."
|
||||
|
@ -0,0 +1,4 @@
|
||||
library L {}
|
||||
contract C { mapping(L => bool) i; }
|
||||
// ----
|
||||
// TypeError: (34-35): Library types cannot be used as mapping keys.
|
Loading…
Reference in New Issue
Block a user