aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--docs/control-structures.rst6
-rw-r--r--docs/frequently-asked-questions.rst17
-rw-r--r--libsolidity/codegen/ExpressionCompiler.cpp2
-rw-r--r--libsolidity/interface/SourceReferenceFormatter.cpp11
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp16
6 files changed, 47 insertions, 7 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 18566bc7..a843ab89 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,7 +8,7 @@ include(EthPolicy)
eth_policy()
# project name and version should be set after cmake_policy CMP0048
-set(PROJECT_VERSION "0.3.0")
+set(PROJECT_VERSION "0.3.1")
project(solidity VERSION ${PROJECT_VERSION})
# Let's find our dependencies
diff --git a/docs/control-structures.rst b/docs/control-structures.rst
index 72cf136d..2d959d1d 100644
--- a/docs/control-structures.rst
+++ b/docs/control-structures.rst
@@ -203,7 +203,7 @@ idea is that assembly libraries will be used to enhance the language in such way
function at(address _addr) returns (bytes o_code) {
assembly {
// retrieve the size of the code, this needs assembly
- let size := extcodesize(_addr);
+ let size := extcodesize(_addr)
// allocate output byte array - this could also be done without assembly
// by using o_code = new bytes(size)
o_code := mload(0x40)
@@ -427,7 +427,7 @@ Strings are stored left-aligned and cannot be longer than 32 bytes.
assembly { 2 3 add "abc" and }
-Functionaly Style
+Functional Style
-----------------
You can type opcode after opcode in the same way they will end up in bytecode. For example
@@ -571,7 +571,7 @@ For both ways, the colon points to the name of the variable.
let v := 0 // functional-style assignment as part of variable declaration
let g := add(v, 2)
sload(10)
- := v // instruction style assignment, puts the result of sload(10) into v
+ =: v // instruction style assignment, puts the result of sload(10) into v
}
diff --git a/docs/frequently-asked-questions.rst b/docs/frequently-asked-questions.rst
index 6ac5a9e9..fc7d7b7f 100644
--- a/docs/frequently-asked-questions.rst
+++ b/docs/frequently-asked-questions.rst
@@ -666,6 +666,23 @@ gas and return your 20 Wei).
In the above example, the low-level function `call` is used to invoke another
contract with `p.data` as payload and `p.amount` Wei is sent with that call.
+What happens to a struct's mapping when copying over a struct?
+==============================================================
+
+This is a very interesting question. Suppose that we have a contract field set up like such::
+
+ struct user{
+ mapping(string => address) usedContracts;
+ }
+ function somefunction{
+ user user1;
+ user1.usedContracts["Hello"] = "World";
+ user user2 = user1;
+ }
+
+In this case, the mapping of the struct being copied over into the userList is ignored as there is no "list of mapped keys".
+Therefore it is not possible to find out which values should be copied over.
+
How do I initialize a contract with only a specific amount of wei?
==================================================================
diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp
index 64eb6710..a17ec2f6 100644
--- a/libsolidity/codegen/ExpressionCompiler.cpp
+++ b/libsolidity/codegen/ExpressionCompiler.cpp
@@ -1069,6 +1069,7 @@ bool ExpressionCompiler::visit(IndexAccess const& _indexAccess)
solAssert(_indexAccess.indexExpression(), "Index expression expected.");
_indexAccess.indexExpression()->accept(*this);
+ utils().convertType(*_indexAccess.indexExpression()->annotation().type, IntegerType(256), true);
// stack layout: <base_ref> [<length>] <index>
ArrayUtils(m_context).accessIndex(arrayType);
switch (arrayType.location())
@@ -1104,6 +1105,7 @@ bool ExpressionCompiler::visit(IndexAccess const& _indexAccess)
solAssert(_indexAccess.indexExpression(), "Index expression expected.");
_indexAccess.indexExpression()->accept(*this);
+ utils().convertType(*_indexAccess.indexExpression()->annotation().type, IntegerType(256), true);
// stack layout: <value> <index>
// check out-of-bounds access
m_context << u256(fixedBytesType.numBytes());
diff --git a/libsolidity/interface/SourceReferenceFormatter.cpp b/libsolidity/interface/SourceReferenceFormatter.cpp
index 65d7fbc8..7b91dd2c 100644
--- a/libsolidity/interface/SourceReferenceFormatter.cpp
+++ b/libsolidity/interface/SourceReferenceFormatter.cpp
@@ -91,7 +91,7 @@ void SourceReferenceFormatter::printExceptionInformation(
auto secondarylocation = boost::get_error_info<errinfo_secondarySourceLocation>(_exception);
Scanner const* scannerPtr = nullptr;
- if (location)
+ if (location && location->sourceName)
{
scannerPtr = &_scannerFromSourceName(*location->sourceName);
printSourceName(_stream, *location, *scannerPtr);
@@ -101,7 +101,7 @@ void SourceReferenceFormatter::printExceptionInformation(
if (string const* description = boost::get_error_info<errinfo_comment>(_exception))
_stream << ": " << *description << endl;
- if (location)
+ if (location && location->sourceName)
{
scannerPtr = &_scannerFromSourceName(*location->sourceName);
printSourceLocation(_stream, *location, *scannerPtr);
@@ -111,8 +111,13 @@ void SourceReferenceFormatter::printExceptionInformation(
{
for (auto info: secondarylocation->infos)
{
- scannerPtr = &_scannerFromSourceName(*info.second.sourceName);
_stream << info.first << " ";
+ if (!info.second.sourceName)
+ {
+ _stream << endl;
+ continue;
+ }
+ scannerPtr = &_scannerFromSourceName(*info.second.sourceName);
printSourceName(_stream, info.second, *scannerPtr);
_stream << endl;
printSourceLocation(_stream, info.second, *scannerPtr);
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 663493c9..c872f011 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -6575,6 +6575,22 @@ BOOST_AUTO_TEST_CASE(inline_assembly_jumps)
BOOST_CHECK(callContractFunction("f()", u256(7)) == encodeArgs(u256(34)));
}
+BOOST_AUTO_TEST_CASE(index_access_with_type_conversion)
+{
+ // Test for a bug where higher order bits cleanup was not done for array index access.
+ char const* sourceCode = R"(
+ contract C {
+ function f(uint x) returns (uint[256] r){
+ r[uint8(x)] = 2;
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+ // neither of the two should throw due to out-of-bounds access
+ BOOST_CHECK(callContractFunction("f(uint256)", u256(0x01)).size() == 256 * 32);
+ BOOST_CHECK(callContractFunction("f(uint256)", u256(0x101)).size() == 256 * 32);
+}
+
BOOST_AUTO_TEST_SUITE_END()
}