mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #2701 from chriseth/sol_fix_stringsAsKeysInMapping
Fix for strings as keys in mappings.
This commit is contained in:
commit
3380c7c6c9
@ -807,16 +807,20 @@ bool ExpressionCompiler::visit(IndexAccess const& _indexAccess)
|
||||
if (baseType.getCategory() == Type::Category::Mapping)
|
||||
{
|
||||
// stack: storage_base_ref
|
||||
auto const& mapping = dynamic_cast<MappingType const&>(baseType);
|
||||
Type const& keyType = *mapping.getKeyType();
|
||||
TypePointer keyType = dynamic_cast<MappingType const&>(baseType).getKeyType();
|
||||
solAssert(_indexAccess.getIndexExpression(), "Index expression expected.");
|
||||
if (keyType.isDynamicallySized())
|
||||
if (keyType->isDynamicallySized())
|
||||
{
|
||||
_indexAccess.getIndexExpression()->accept(*this);
|
||||
utils().fetchFreeMemoryPointer();
|
||||
// stack: base index mem
|
||||
// note: the following operations must not allocate memory!
|
||||
utils().encodeToMemory(TypePointers{mapping.getKeyType()}, TypePointers(), false, true);
|
||||
utils().encodeToMemory(
|
||||
TypePointers{_indexAccess.getIndexExpression()->getType()},
|
||||
TypePointers{keyType},
|
||||
false,
|
||||
true
|
||||
);
|
||||
m_context << eth::Instruction::SWAP1;
|
||||
utils().storeInMemoryDynamic(IntegerType(256));
|
||||
utils().toSizeAfterFreeMemoryPointer();
|
||||
@ -824,7 +828,7 @@ bool ExpressionCompiler::visit(IndexAccess const& _indexAccess)
|
||||
else
|
||||
{
|
||||
m_context << u256(0); // memory position
|
||||
appendExpressionCopyToMemory(keyType, *_indexAccess.getIndexExpression());
|
||||
appendExpressionCopyToMemory(*keyType, *_indexAccess.getIndexExpression());
|
||||
m_context << eth::Instruction::SWAP1;
|
||||
solAssert(CompilerUtils::freeMemoryPointer >= 0x40, "");
|
||||
utils().storeInMemoryDynamic(IntegerType(256));
|
||||
|
Loading…
Reference in New Issue
Block a user