Merge pull request #2701 from chriseth/sol_fix_stringsAsKeysInMapping

Fix for strings as keys in mappings.
This commit is contained in:
chriseth 2015-08-05 15:59:44 +02:00
commit 3380c7c6c9

View File

@ -807,16 +807,20 @@ bool ExpressionCompiler::visit(IndexAccess const& _indexAccess)
if (baseType.getCategory() == Type::Category::Mapping) if (baseType.getCategory() == Type::Category::Mapping)
{ {
// stack: storage_base_ref // stack: storage_base_ref
auto const& mapping = dynamic_cast<MappingType const&>(baseType); TypePointer keyType = dynamic_cast<MappingType const&>(baseType).getKeyType();
Type const& keyType = *mapping.getKeyType();
solAssert(_indexAccess.getIndexExpression(), "Index expression expected."); solAssert(_indexAccess.getIndexExpression(), "Index expression expected.");
if (keyType.isDynamicallySized()) if (keyType->isDynamicallySized())
{ {
_indexAccess.getIndexExpression()->accept(*this); _indexAccess.getIndexExpression()->accept(*this);
utils().fetchFreeMemoryPointer(); utils().fetchFreeMemoryPointer();
// stack: base index mem // stack: base index mem
// note: the following operations must not allocate memory! // 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; m_context << eth::Instruction::SWAP1;
utils().storeInMemoryDynamic(IntegerType(256)); utils().storeInMemoryDynamic(IntegerType(256));
utils().toSizeAfterFreeMemoryPointer(); utils().toSizeAfterFreeMemoryPointer();
@ -824,7 +828,7 @@ bool ExpressionCompiler::visit(IndexAccess const& _indexAccess)
else else
{ {
m_context << u256(0); // memory position m_context << u256(0); // memory position
appendExpressionCopyToMemory(keyType, *_indexAccess.getIndexExpression()); appendExpressionCopyToMemory(*keyType, *_indexAccess.getIndexExpression());
m_context << eth::Instruction::SWAP1; m_context << eth::Instruction::SWAP1;
solAssert(CompilerUtils::freeMemoryPointer >= 0x40, ""); solAssert(CompilerUtils::freeMemoryPointer >= 0x40, "");
utils().storeInMemoryDynamic(IntegerType(256)); utils().storeInMemoryDynamic(IntegerType(256));