aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Changelog.md7
-rw-r--r--docs/contracts.rst33
-rw-r--r--docs/control-structures.rst4
-rw-r--r--docs/frequently-asked-questions.rst9
-rw-r--r--docs/installing-solidity.rst2
-rw-r--r--docs/types.rst4
-rw-r--r--libsolidity/analysis/ReferencesResolver.cpp17
-rw-r--r--libsolidity/analysis/SyntaxChecker.cpp13
-rw-r--r--libsolidity/analysis/SyntaxChecker.h2
-rw-r--r--libsolidity/analysis/TypeChecker.cpp117
-rw-r--r--libsolidity/ast/AST.cpp7
-rw-r--r--libsolidity/ast/AST.h2
-rw-r--r--libsolidity/ast/ASTAnnotations.h7
-rw-r--r--libsolidity/ast/ASTJsonConverter.cpp4
-rw-r--r--libsolidity/codegen/CompilerContext.cpp25
-rw-r--r--libsolidity/codegen/CompilerContext.h6
-rw-r--r--libsolidity/codegen/CompilerUtils.cpp9
-rw-r--r--libsolidity/codegen/CompilerUtils.h4
-rw-r--r--libsolidity/codegen/ContractCompiler.cpp118
-rw-r--r--libsolidity/codegen/ContractCompiler.h24
-rw-r--r--libsolidity/codegen/ExpressionCompiler.cpp16
-rw-r--r--libsolidity/interface/Natspec.cpp7
-rw-r--r--test/compilationTests/MultiSigWallet/MultiSigWallet.sol2
-rw-r--r--test/compilationTests/MultiSigWallet/MultiSigWalletWithDailyLimit.sol2
-rw-r--r--test/compilationTests/milestonetracker/MilestoneTracker.sol16
-rw-r--r--test/compilationTests/zeppelin/token/VestedToken.sol4
-rw-r--r--test/contracts/AuctionRegistrar.cpp2
-rw-r--r--test/contracts/FixedFeeRegistrar.cpp4
-rw-r--r--test/contracts/Wallet.cpp6
-rw-r--r--test/libsolidity/ASTJSON.cpp2
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp389
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp4
-rw-r--r--test/libsolidity/SolidityOptimizer.cpp6
-rw-r--r--test/libsolidity/syntaxTests/dataLocations/variable_declaration_location_specifier_test_reference_type.sol3
-rw-r--r--test/libsolidity/syntaxTests/multiVariableDeclaration/differentNumberOfComponents.sol25
-rw-r--r--test/libsolidity/syntaxTests/multiVariableDeclaration/differentNumberOfComponentsFromReturn.sol29
-rw-r--r--test/libsolidity/syntaxTests/multiVariableDeclaration/disallowWildcards.sol24
-rw-r--r--test/libsolidity/syntaxTests/multiVariableDeclaration/disallowWildcardsFromReturn.sol31
-rw-r--r--test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationComplex.sol8
-rw-r--r--test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationEmpty.sol11
-rw-r--r--test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationSimple.sol10
-rw-r--r--test/libsolidity/syntaxTests/multiVariableDeclaration/oneElementTuple.sol8
-rw-r--r--test/libsolidity/syntaxTests/multiVariableDeclaration/sameNumberOfComponents.sol9
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/232_literal_string_to_storage_pointer.sol5
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/239_multi_variable_declaration_wildcards_fine.sol19
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/240_multi_variable_declaration_wildcards_fail_1.sol7
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/241_multi_variable_declaration_wildcards_fail_2.sol7
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/242_multi_variable_declaration_wildcards_fail_3.sol7
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/243_multi_variable_declaration_wildcards_fail_4.sol7
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/244_tuples.sol9
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/246_multi_variable_declaration_wildcards_fail_5.sol6
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/247_multi_variable_declaration_wildcards_fail_6.sol7
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/250_member_access_parser_ambiguity.sol5
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/276_invalid_types_in_inline_array.sol5
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/471_unspecified_storage_fail.sol13
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/471_unspecified_storage_warn.sol10
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/472_unspecified_storage_v050.sol11
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/481_explicit_literal_to_unspecified_string_assignment.sol5
-rw-r--r--test/libsolidity/syntaxTests/parsing/arrays_in_expressions.sol8
-rw-r--r--test/libsolidity/syntaxTests/parsing/multi_variable_declarations.sol6
-rw-r--r--test/libsolidity/syntaxTests/parsing/tuples.sol13
-rw-r--r--test/libsolidity/syntaxTests/structs/recursion/struct_definition_directly_recursive_dynamic_array.sol7
-rw-r--r--test/libsolidity/syntaxTests/structs/recursion/struct_definition_directly_recursive_fixed_array.sol8
-rw-r--r--test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_complex.sol18
-rw-r--r--test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_array1.sol11
-rw-r--r--test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_array2.sol11
-rw-r--r--test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_array3.sol11
-rw-r--r--test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_multi_array.sol21
-rw-r--r--test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_array1.sol12
-rw-r--r--test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_array2.sol12
-rw-r--r--test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_array3.sol12
-rw-r--r--test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_multi_array.sol12
-rw-r--r--test/libsolidity/syntaxTests/structs/recursion/struct_definition_not_really_recursive_array.sol4
-rw-r--r--test/libsolidity/syntaxTests/tupleAssignments/warn_fill_vardecl.sol8
-rw-r--r--test/libsolidity/syntaxTests/types/unnamed_tuple_decl.sol18
75 files changed, 981 insertions, 366 deletions
diff --git a/Changelog.md b/Changelog.md
index fbdf9206..b27254a8 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -4,12 +4,14 @@ How to update your code:
* Change every ``.call()`` to a ``.call("")`` and every ``.call(signature, a, b, c)`` to use ``.call(abi.encodeWithSignature(signature, a, b, c))`` (the last one only works for value types).
* Change every ``keccak256(a, b, c)`` to ``keccak256(abi.encodePacked(a, b, c))``.
* Make your fallback functions ``external``.
+ * Explicitly state the storage location for local variables of struct and array types, e.g. change ``uint[] x = m_x`` to ``uint[] storage x = m_x``.
Breaking Changes:
* ABI Encoder: Properly pad data from calldata (``msg.data`` and external function parameters). Use ``abi.encodePacked`` for unpadded encoding.
* Code Generator: Signed right shift uses proper arithmetic shift, i.e. rounding towards negative infinity. Warning: this may silently change the semantics of existing code!
* Code Generator: Revert at runtime if calldata is too short or points out of bounds. This is done inside the ``ABI decoder`` and therefore also applies to ``abi.decode()``.
+ * Code Generator: Use ``STATICCALL`` for ``pure`` and ``view`` functions. This was already the case in the experimental 0.5.0 mode.
* Commandline interface: Remove obsolete ``--formal`` option.
* Commandline interface: Rename the ``--julia`` option to ``--yul``.
* Commandline interface: Require ``-`` if standard input is used as source.
@@ -36,12 +38,14 @@ Breaking Changes:
* Type Checker: Disallow tight packing of literals. This was already the case in the experimental 0.5.0 mode.
* Type Checker: Disallow conversions between ``bytesX`` and ``uintY`` of different size.
* Type Checker: Disallow empty tuple components. This was partly already the case in the experimental 0.5.0 mode.
+ * Type Checker: Disallow multi-variable declarations with mismatching number of values. This was already the case in the experimental 0.5.0 mode.
* Type Checker: Disallow specifying base constructor arguments multiple times in the same inheritance hierarchy. This was already the case in the experimental 0.5.0 mode.
* Type Checker: Disallow calling constructor with wrong argument count. This was already the case in the experimental 0.5.0 mode.
* Type Checker: Disallow uninitialized storage variables. This was already the case in the experimental 0.5.0 mode.
* Type Checker: Only accept a single ``bytes`` type for ``.call()`` (and family), ``keccak256()``, ``sha256()`` and ``ripemd160()``.
* Type Checker: Fallback function must be external. This was already the case in the experimental 0.5.0 mode.
* Remove obsolete ``std`` directory from the Solidity repository. This means accessing ``https://github.com/ethereum/soldity/blob/develop/std/*.sol`` (or ``https://github.com/ethereum/solidity/std/*.sol`` in Remix) will not be possible.
+ * References Resolver: Turn missing storage locations into an error. This was already the case in the experimental 0.5.0 mode.
* Syntax Checker: Named return values in function types are an error.
* Syntax Checker: Disallow unary ``+``. This was already the case in the experimental 0.5.0 mode.
* View Pure Checker: Strictly enfore state mutability. This was already the case in the experimental 0.5.0 mode.
@@ -55,10 +59,13 @@ Compiler Features:
* C API (``libsolc``): Export the ``solidity_license``, ``solidity_version`` and ``solidity_compile`` methods.
* Type Checker: Show named argument in case of error.
* Tests: Determine transaction status during IPC calls.
+ * Code Generator: Allocate and free local variables according to their scope.
Bugfixes:
* Tests: Fix chain parameters to make ipc tests work with newer versions of cpp-ethereum.
* Code Generator: Fix allocation of byte arrays (zeroed out too much memory).
+ * Fix NatSpec json output for `@notice` and `@dev` tags on contract definitions.
+ * Type Checker: Consider fixed size arrays when checking for recursive structs.
* Type System: Allow arbitrary exponents for literals with a mantissa of zero.
### 0.4.24 (2018-05-16)
diff --git a/docs/contracts.rst b/docs/contracts.rst
index e3dd04be..fa6df6bf 100644
--- a/docs/contracts.rst
+++ b/docs/contracts.rst
@@ -451,6 +451,10 @@ View Functions
Functions can be declared ``view`` in which case they promise not to modify the state.
+.. note::
+ If the compiler's EVM target is Byzantium or newer (default) the opcode
+ ``STATICCALL`` is used.
+
The following statements are considered modifying the state:
#. Writing to state variables.
@@ -464,7 +468,7 @@ The following statements are considered modifying the state:
::
- pragma solidity ^0.4.16;
+ pragma solidity >0.4.24;
contract C {
function f(uint a, uint b) public view returns (uint) {
@@ -479,11 +483,12 @@ The following statements are considered modifying the state:
Getter methods are marked ``view``.
.. note::
- If invalid explicit type conversions are used, state modifications are possible
- even though a ``view`` function was called.
- You can switch the compiler to use ``STATICCALL`` when calling such functions and thus
- prevent modifications to the state on the level of the EVM by adding
- ``pragma experimental "v0.5.0";``
+ Prior to version 0.5.0, the compiler did not use the ``STATICCALL`` opcode
+ for ``view`` functions.
+ This enabled state modifications in ``view`` functions through the use of
+ invalid explicit type conversions.
+ By using ``STATICCALL`` for ``view`` functions, modifications to the
+ state are prevented on the level of the EVM.
.. index:: ! pure function, function;pure
@@ -494,6 +499,9 @@ Pure Functions
Functions can be declared ``pure`` in which case they promise not to read from or modify the state.
+.. note::
+ If the compiler's EVM target is Byzantium or newer (default) the opcode ``STATICCALL`` is used.
+
In addition to the list of state modifying statements explained above, the following are considered reading from the state:
#. Reading from state variables.
@@ -504,7 +512,7 @@ In addition to the list of state modifying statements explained above, the follo
::
- pragma solidity ^0.4.16;
+ pragma solidity >0.4.24;
contract C {
function f(uint a, uint b) public pure returns (uint) {
@@ -513,11 +521,12 @@ In addition to the list of state modifying statements explained above, the follo
}
.. note::
- If invalid explicit type conversions are used, state modifications are possible
- even though a ``pure`` function was called.
- You can switch the compiler to use ``STATICCALL`` when calling such functions and thus
- prevent modifications to the state on the level of the EVM by adding
- ``pragma experimental "v0.5.0";``
+ Prior to version 0.5.0, the compiler did not use the ``STATICCALL`` opcode
+ for ``pure`` functions.
+ This enabled state modifications in ``pure`` functions through the use of
+ invalid explicit type conversions.
+ By using ``STATICCALL`` for ``pure`` functions, modifications to the
+ state are prevented on the level of the EVM.
.. warning::
It is not possible to prevent functions from reading the state at the level
diff --git a/docs/control-structures.rst b/docs/control-structures.rst
index 52a07861..ead236c4 100644
--- a/docs/control-structures.rst
+++ b/docs/control-structures.rst
@@ -297,9 +297,9 @@ These can then either be assigned to newly declared variables or to pre-existing
}
.. note::
- Prior to version 0.4.24 it was possible to assign to tuples of smaller size, either
+ Prior to version 0.5.0 it was possible to assign to tuples of smaller size, either
filling up on the left or on the right side (which ever was empty). This is
- now deprecated, both sides have to have the same number of components.
+ now disallowed, so both sides have to have the same number of components.
Complications for Arrays and Structs
------------------------------------
diff --git a/docs/frequently-asked-questions.rst b/docs/frequently-asked-questions.rst
index e64849ea..17e71747 100644
--- a/docs/frequently-asked-questions.rst
+++ b/docs/frequently-asked-questions.rst
@@ -273,9 +273,11 @@ of variable it concerns:
* state variables are always in storage
* function arguments are in memory by default
-* local variables of struct, array or mapping type reference storage by default
+* local variables of mapping type reference storage by default
* local variables of value type (i.e. neither array, nor struct nor mapping) are stored in the stack
+For local variables of struct or array type the storage location has to be stated explicitly.
+
Example::
pragma solidity ^0.4.0;
@@ -309,8 +311,9 @@ carry back to ``data1`` or ``data2``.
.. warning::
Prior to version 0.5.0, a common mistake was to declare a local variable and assume that it will
be created in memory, although it will be created in storage. Using such a variable without initializing
- it could lead to unexpected behavior. Starting from 0.5.0, however, storage variables have to be initialized,
- which should prevent these kinds of mistakes.
+ could lead to unexpected behavior. Starting from 0.5.0, however, the storage location for local variables
+ has to be specified explicitly and local storage variables have to be initialized, which should prevent
+ these kinds of mistakes.
******************
Advanced Questions
diff --git a/docs/installing-solidity.rst b/docs/installing-solidity.rst
index 05ee0748..5b3fdf87 100644
--- a/docs/installing-solidity.rst
+++ b/docs/installing-solidity.rst
@@ -64,7 +64,7 @@ repository contains potentially unstable changes in the develop branch.
.. code:: bash
- docker run ethereum/solc:stable solc --version
+ docker run ethereum/solc:stable --version
Currently, the docker image only contains the compiler executable,
so you have to do some additional work to link in the source and
diff --git a/docs/types.rst b/docs/types.rst
index 217a2273..16445a34 100644
--- a/docs/types.rst
+++ b/docs/types.rst
@@ -386,10 +386,6 @@ By default, function types are internal, so the ``internal`` keyword can be
omitted. In contrast, contract functions themselves are public by default,
only when used as the name of a type, the default is internal.
-There are two ways to access a function in the current contract: Either directly
-by its name, ``f``, or using ``this.f``. The former will result in an internal
-function, the latter in an external function.
-
If a function type variable is not initialized, calling it will result
in an exception. The same happens if you call a function after using ``delete``
on it.
diff --git a/libsolidity/analysis/ReferencesResolver.cpp b/libsolidity/analysis/ReferencesResolver.cpp
index 58b659f7..dfcbf888 100644
--- a/libsolidity/analysis/ReferencesResolver.cpp
+++ b/libsolidity/analysis/ReferencesResolver.cpp
@@ -377,19 +377,10 @@ void ReferencesResolver::endVisit(VariableDeclaration const& _variable)
{
typeLoc = DataLocation::Storage;
if (_variable.isLocalVariable())
- {
- if (_variable.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050))
- typeError(
- _variable.location(),
- "Data location must be specified as either \"memory\" or \"storage\"."
- );
- else
- m_errorReporter.warning(
- _variable.location(),
- "Variable is declared as a storage pointer. "
- "Use an explicit \"storage\" keyword to silence this warning."
- );
- }
+ typeError(
+ _variable.location(),
+ "Data location must be specified as either \"memory\" or \"storage\"."
+ );
}
}
else
diff --git a/libsolidity/analysis/SyntaxChecker.cpp b/libsolidity/analysis/SyntaxChecker.cpp
index 4311e77d..e33aafed 100644
--- a/libsolidity/analysis/SyntaxChecker.cpp
+++ b/libsolidity/analysis/SyntaxChecker.cpp
@@ -22,6 +22,7 @@
#include <libsolidity/analysis/SemVerHandler.h>
#include <libsolidity/interface/ErrorReporter.h>
#include <libsolidity/interface/Version.h>
+#include <boost/algorithm/cxx11/all_of.hpp>
using namespace std;
using namespace dev;
@@ -254,6 +255,18 @@ bool SyntaxChecker::visit(FunctionTypeName const& _node)
return true;
}
+bool SyntaxChecker::visit(VariableDeclarationStatement const& _statement)
+{
+ // Report if none of the variable components in the tuple have a name (only possible via deprecated "var")
+ if (boost::algorithm::all_of_equal(_statement.declarations(), nullptr))
+ m_errorReporter.syntaxError(
+ _statement.location(),
+ "The use of the \"var\" keyword is disallowed. The declaration part of the statement can be removed, since it is empty."
+ );
+
+ return true;
+}
+
bool SyntaxChecker::visit(StructDefinition const& _struct)
{
if (_struct.members().empty())
diff --git a/libsolidity/analysis/SyntaxChecker.h b/libsolidity/analysis/SyntaxChecker.h
index 8ee3df37..5460e3be 100644
--- a/libsolidity/analysis/SyntaxChecker.h
+++ b/libsolidity/analysis/SyntaxChecker.h
@@ -69,6 +69,8 @@ private:
virtual bool visit(FunctionDefinition const& _function) override;
virtual bool visit(FunctionTypeName const& _node) override;
+ virtual bool visit(VariableDeclarationStatement const& _statement) override;
+
virtual bool visit(StructDefinition const& _struct) override;
ErrorReporter& m_errorReporter;
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 8ea0a4d7..cc373e03 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -30,6 +30,7 @@
#include <libsolidity/inlineasm/AsmAnalysisInfo.h>
#include <libsolidity/inlineasm/AsmData.h>
#include <libsolidity/interface/ErrorReporter.h>
+#include <libdevcore/Algorithms.h>
using namespace std;
using namespace dev;
@@ -593,22 +594,24 @@ bool TypeChecker::visit(StructDefinition const& _struct)
m_errorReporter.typeError(member->location(), "Type cannot be used in struct.");
// Check recursion, fatal error if detected.
- using StructPointer = StructDefinition const*;
- using StructPointersSet = set<StructPointer>;
- function<void(StructPointer,StructPointersSet const&)> check = [&](StructPointer _struct, StructPointersSet const& _parents)
- {
- if (_parents.count(_struct))
- m_errorReporter.fatalTypeError(_struct->location(), "Recursive struct definition.");
- StructPointersSet parents = _parents;
- parents.insert(_struct);
- for (ASTPointer<VariableDeclaration> const& member: _struct->members())
- if (type(*member)->category() == Type::Category::Struct)
+ auto visitor = [&](StructDefinition const& _struct, CycleDetector<StructDefinition>& _cycleDetector)
+ {
+ for (ASTPointer<VariableDeclaration> const& member: _struct.members())
+ {
+ Type const* memberType = type(*member).get();
+ while (auto arrayType = dynamic_cast<ArrayType const*>(memberType))
{
- auto const& typeName = dynamic_cast<UserDefinedTypeName const&>(*member->typeName());
- check(&dynamic_cast<StructDefinition const&>(*typeName.annotation().referencedDeclaration), parents);
+ if (arrayType->isDynamicallySized())
+ break;
+ memberType = arrayType->baseType().get();
}
+ if (auto structType = dynamic_cast<StructType const*>(memberType))
+ if (_cycleDetector.run(structType->structDefinition()))
+ return;
+ }
};
- check(&_struct, StructPointersSet{});
+ if (CycleDetector<StructDefinition>(visitor).run(_struct) != nullptr)
+ m_errorReporter.fatalTypeError(_struct.location(), "Recursive struct definition.");
ASTNode::listAccept(_struct.members(), *this);
@@ -1043,10 +1046,10 @@ namespace
* @returns a suggested left-hand-side of a multi-variable declaration contairing
* the variable declarations given in @a _decls.
*/
-string createTupleDecl(vector<VariableDeclaration const*> const& _decls)
+string createTupleDecl(vector<ASTPointer<VariableDeclaration>> const& _decls)
{
vector<string> components;
- for (VariableDeclaration const* decl: _decls)
+ for (ASTPointer<VariableDeclaration> const& decl: _decls)
if (decl)
components.emplace_back(decl->annotation().type->toString(false) + " " + decl->name());
else
@@ -1058,9 +1061,9 @@ string createTupleDecl(vector<VariableDeclaration const*> const& _decls)
return "(" + boost::algorithm::join(components, ", ") + ")";
}
-bool typeCanBeExpressed(vector<VariableDeclaration const*> const& decls)
+bool typeCanBeExpressed(vector<ASTPointer<VariableDeclaration>> const& decls)
{
- for (VariableDeclaration const* decl: decls)
+ for (ASTPointer<VariableDeclaration> const& decl: decls)
{
// skip empty tuples (they can be expressed of course)
if (!decl)
@@ -1080,7 +1083,6 @@ bool typeCanBeExpressed(vector<VariableDeclaration const*> const& decls)
bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
{
- bool const v050 = m_scope->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050);
if (!_statement.initialValue())
{
// No initial value is only permitted for single variables with specified type.
@@ -1119,82 +1121,27 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
else
valueTypes = TypePointers{type(*_statement.initialValue())};
- // Determine which component is assigned to which variable.
- // If numbers do not match, fill up if variables begin or end empty (not both).
- vector<VariableDeclaration const*>& assignments = _statement.annotation().assignments;
- assignments.resize(valueTypes.size(), nullptr);
vector<ASTPointer<VariableDeclaration>> const& variables = _statement.declarations();
if (variables.empty())
- {
- if (!valueTypes.empty())
- m_errorReporter.fatalTypeError(
- _statement.location(),
- "Too many components (" +
- toString(valueTypes.size()) +
- ") in value for variable assignment (0) needed"
- );
- }
+ // We already have an error for this in the SyntaxChecker.
+ solAssert(m_errorReporter.hasErrors(), "");
else if (valueTypes.size() != variables.size())
- {
- if (v050)
- m_errorReporter.fatalTypeError(
- _statement.location(),
- "Different number of components on the left hand side (" +
- toString(variables.size()) +
- ") than on the right hand side (" +
- toString(valueTypes.size()) +
- ")."
- );
- else if (!variables.front() && !variables.back())
- m_errorReporter.fatalTypeError(
- _statement.location(),
- "Wildcard both at beginning and end of variable declaration list is only allowed "
- "if the number of components is equal."
- );
- else
- m_errorReporter.warning(
- _statement.location(),
- "Different number of components on the left hand side (" +
- toString(variables.size()) +
- ") than on the right hand side (" +
- toString(valueTypes.size()) +
- ")."
- );
- }
- size_t minNumValues = variables.size();
- if (!variables.empty() && (!variables.back() || !variables.front()))
- --minNumValues;
- if (valueTypes.size() < minNumValues)
- m_errorReporter.fatalTypeError(
- _statement.location(),
- "Not enough components (" +
- toString(valueTypes.size()) +
- ") in value to assign all variables (" +
- toString(minNumValues) + ")."
- );
- if (valueTypes.size() > variables.size() && variables.front() && variables.back())
- m_errorReporter.fatalTypeError(
+ m_errorReporter.typeError(
_statement.location(),
- "Too many components (" +
+ "Different number of components on the left hand side (" +
+ toString(variables.size()) +
+ ") than on the right hand side (" +
toString(valueTypes.size()) +
- ") in value for variable assignment (" +
- toString(minNumValues) +
- " needed)."
+ ")."
);
- bool fillRight = !variables.empty() && (!variables.back() || variables.front());
- for (size_t i = 0; i < min(variables.size(), valueTypes.size()); ++i)
- if (fillRight)
- assignments[i] = variables[i].get();
- else
- assignments[assignments.size() - i - 1] = variables[variables.size() - i - 1].get();
bool autoTypeDeductionNeeded = false;
- for (size_t i = 0; i < assignments.size(); ++i)
+ for (size_t i = 0; i < min(variables.size(), valueTypes.size()); ++i)
{
- if (!assignments[i])
+ if (!variables[i])
continue;
- VariableDeclaration const& var = *assignments[i];
+ VariableDeclaration const& var = *variables[i];
solAssert(!var.value(), "Value has to be tied to statement.");
TypePointer const& valueComponentType = valueTypes[i];
solAssert(!!valueComponentType, "");
@@ -1284,7 +1231,7 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
if (autoTypeDeductionNeeded)
{
- if (!typeCanBeExpressed(assignments))
+ if (!typeCanBeExpressed(variables))
m_errorReporter.syntaxError(
_statement.location(),
"Use of the \"var\" keyword is disallowed. "
@@ -1294,7 +1241,7 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
m_errorReporter.syntaxError(
_statement.location(),
"Use of the \"var\" keyword is disallowed. "
- "Use explicit declaration `" + createTupleDecl(assignments) + " = ...´ instead."
+ "Use explicit declaration `" + createTupleDecl(variables) + " = ...´ instead."
);
}
diff --git a/libsolidity/ast/AST.cpp b/libsolidity/ast/AST.cpp
index 16c9b2d2..7719d080 100644
--- a/libsolidity/ast/AST.cpp
+++ b/libsolidity/ast/AST.cpp
@@ -535,13 +535,6 @@ ReturnAnnotation& Return::annotation() const
return dynamic_cast<ReturnAnnotation&>(*m_annotation);
}
-VariableDeclarationStatementAnnotation& VariableDeclarationStatement::annotation() const
-{
- if (!m_annotation)
- m_annotation = new VariableDeclarationStatementAnnotation();
- return dynamic_cast<VariableDeclarationStatementAnnotation&>(*m_annotation);
-}
-
ExpressionAnnotation& Expression::annotation() const
{
if (!m_annotation)
diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h
index e862fd62..acd90ad8 100644
--- a/libsolidity/ast/AST.h
+++ b/libsolidity/ast/AST.h
@@ -1270,8 +1270,6 @@ public:
virtual void accept(ASTVisitor& _visitor) override;
virtual void accept(ASTConstVisitor& _visitor) const override;
- VariableDeclarationStatementAnnotation& annotation() const override;
-
std::vector<ASTPointer<VariableDeclaration>> const& declarations() const { return m_variables; }
Expression const* initialValue() const { return m_initialValue.get(); }
diff --git a/libsolidity/ast/ASTAnnotations.h b/libsolidity/ast/ASTAnnotations.h
index 5cbe42bd..e0b3f492 100644
--- a/libsolidity/ast/ASTAnnotations.h
+++ b/libsolidity/ast/ASTAnnotations.h
@@ -164,13 +164,6 @@ struct UserDefinedTypeNameAnnotation: TypeNameAnnotation
ContractDefinition const* contractScope = nullptr;
};
-struct VariableDeclarationStatementAnnotation: StatementAnnotation
-{
- /// Information about which component of the value is assigned to which variable.
- /// The pointer can be null to signify that the component is discarded.
- std::vector<VariableDeclaration const*> assignments;
-};
-
struct ExpressionAnnotation: ASTAnnotation
{
/// Inferred type of the expression.
diff --git a/libsolidity/ast/ASTJsonConverter.cpp b/libsolidity/ast/ASTJsonConverter.cpp
index b7855668..a26828a6 100644
--- a/libsolidity/ast/ASTJsonConverter.cpp
+++ b/libsolidity/ast/ASTJsonConverter.cpp
@@ -555,8 +555,8 @@ bool ASTJsonConverter::visit(EmitStatement const& _node)
bool ASTJsonConverter::visit(VariableDeclarationStatement const& _node)
{
Json::Value varDecs(Json::arrayValue);
- for (auto const& v: _node.annotation().assignments)
- appendMove(varDecs, idOrNull(v));
+ for (auto const& v: _node.declarations())
+ appendMove(varDecs, idOrNull(v.get()));
setJsonNode(_node, "VariableDeclarationStatement", {
make_pair("assignments", std::move(varDecs)),
make_pair("declarations", toJson(_node.declarations())),
diff --git a/libsolidity/codegen/CompilerContext.cpp b/libsolidity/codegen/CompilerContext.cpp
index a35eea73..3b1b4ec0 100644
--- a/libsolidity/codegen/CompilerContext.cpp
+++ b/libsolidity/codegen/CompilerContext.cpp
@@ -127,10 +127,14 @@ void CompilerContext::addVariable(VariableDeclaration const& _declaration,
unsigned _offsetToCurrent)
{
solAssert(m_asm->deposit() >= 0 && unsigned(m_asm->deposit()) >= _offsetToCurrent, "");
+ unsigned sizeOnStack = _declaration.annotation().type->sizeOnStack();
+ // Variables should not have stack size other than [1, 2],
+ // but that might change when new types are introduced.
+ solAssert(sizeOnStack == 1 || sizeOnStack == 2, "");
m_localVariables[&_declaration].push_back(unsigned(m_asm->deposit()) - _offsetToCurrent);
}
-void CompilerContext::removeVariable(VariableDeclaration const& _declaration)
+void CompilerContext::removeVariable(Declaration const& _declaration)
{
solAssert(m_localVariables.count(&_declaration) && !m_localVariables[&_declaration].empty(), "");
m_localVariables[&_declaration].pop_back();
@@ -138,6 +142,25 @@ void CompilerContext::removeVariable(VariableDeclaration const& _declaration)
m_localVariables.erase(&_declaration);
}
+void CompilerContext::removeVariablesAboveStackHeight(unsigned _stackHeight)
+{
+ vector<Declaration const*> toRemove;
+ for (auto _var: m_localVariables)
+ {
+ solAssert(!_var.second.empty(), "");
+ solAssert(_var.second.back() <= stackHeight(), "");
+ if (_var.second.back() >= _stackHeight)
+ toRemove.push_back(_var.first);
+ }
+ for (auto _var: toRemove)
+ removeVariable(*_var);
+}
+
+unsigned CompilerContext::numberOfLocalVariables() const
+{
+ return m_localVariables.size();
+}
+
eth::Assembly const& CompilerContext::compiledContract(const ContractDefinition& _contract) const
{
auto ret = m_compiledContracts.find(&_contract);
diff --git a/libsolidity/codegen/CompilerContext.h b/libsolidity/codegen/CompilerContext.h
index 5776b5d1..3f357821 100644
--- a/libsolidity/codegen/CompilerContext.h
+++ b/libsolidity/codegen/CompilerContext.h
@@ -71,7 +71,11 @@ public:
void addStateVariable(VariableDeclaration const& _declaration, u256 const& _storageOffset, unsigned _byteOffset);
void addVariable(VariableDeclaration const& _declaration, unsigned _offsetToCurrent = 0);
- void removeVariable(VariableDeclaration const& _declaration);
+ void removeVariable(Declaration const& _declaration);
+ /// Removes all local variables currently allocated above _stackHeight.
+ void removeVariablesAboveStackHeight(unsigned _stackHeight);
+ /// Returns the number of currently allocated local variables.
+ unsigned numberOfLocalVariables() const;
void setCompiledContracts(std::map<ContractDefinition const*, eth::Assembly const*> const& _contracts) { m_compiledContracts = _contracts; }
eth::Assembly const& compiledContract(ContractDefinition const& _contract) const;
diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp
index 2e335ca5..2d81a106 100644
--- a/libsolidity/codegen/CompilerUtils.cpp
+++ b/libsolidity/codegen/CompilerUtils.cpp
@@ -1170,6 +1170,15 @@ void CompilerUtils::popStackSlots(size_t _amount)
m_context << Instruction::POP;
}
+void CompilerUtils::popAndJump(unsigned _toHeight, eth::AssemblyItem const& _jumpTo)
+{
+ solAssert(m_context.stackHeight() >= _toHeight, "");
+ unsigned amount = m_context.stackHeight() - _toHeight;
+ popStackSlots(amount);
+ m_context.appendJumpTo(_jumpTo);
+ m_context.adjustStackOffset(amount);
+}
+
unsigned CompilerUtils::sizeOnStack(vector<shared_ptr<Type const>> const& _variableTypes)
{
unsigned size = 0;
diff --git a/libsolidity/codegen/CompilerUtils.h b/libsolidity/codegen/CompilerUtils.h
index 0ff3ad7c..26df4765 100644
--- a/libsolidity/codegen/CompilerUtils.h
+++ b/libsolidity/codegen/CompilerUtils.h
@@ -241,6 +241,10 @@ public:
void popStackElement(Type const& _type);
/// Removes element from the top of the stack _amount times.
void popStackSlots(size_t _amount);
+ /// Pops slots from the stack such that its height is _toHeight.
+ /// Adds jump to _jumpTo.
+ /// Readjusts the stack offset to the original value.
+ void popAndJump(unsigned _toHeight, eth::AssemblyItem const& _jumpTo);
template <class T>
static unsigned sizeOnStack(std::vector<T> const& _variables);
diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp
index 81aba21e..bbb3db3d 100644
--- a/libsolidity/codegen/ContractCompiler.cpp
+++ b/libsolidity/codegen/ContractCompiler.cpp
@@ -427,7 +427,7 @@ bool ContractCompiler::visit(FunctionDefinition const& _function)
m_context.startFunction(_function);
// stack upon entry: [return address] [arg0] [arg1] ... [argn]
- // reserve additional slots: [retarg0] ... [retargm] [localvar0] ... [localvarp]
+ // reserve additional slots: [retarg0] ... [retargm]
unsigned parametersSize = CompilerUtils::sizeOnStack(_function.parameters());
if (!_function.isConstructor())
@@ -441,8 +441,6 @@ bool ContractCompiler::visit(FunctionDefinition const& _function)
for (ASTPointer<VariableDeclaration const> const& variable: _function.returnParameters())
appendStackVariableInitialisation(*variable);
- for (VariableDeclaration const* localVariable: _function.localVariables())
- appendStackVariableInitialisation(*localVariable);
if (_function.isConstructor())
if (auto c = m_context.nextConstructor(dynamic_cast<ContractDefinition const&>(*_function.scope())))
@@ -451,12 +449,11 @@ bool ContractCompiler::visit(FunctionDefinition const& _function)
solAssert(m_returnTags.empty(), "");
m_breakTags.clear();
m_continueTags.clear();
- m_stackCleanupForReturn = 0;
m_currentFunction = &_function;
m_modifierDepth = -1;
+ m_scopeStackHeight.clear();
appendModifierOrFunctionCode();
-
solAssert(m_returnTags.empty(), "");
// Now we need to re-shuffle the stack. For this we keep a record of the stack layout
@@ -467,14 +464,12 @@ bool ContractCompiler::visit(FunctionDefinition const& _function)
unsigned const c_argumentsSize = CompilerUtils::sizeOnStack(_function.parameters());
unsigned const c_returnValuesSize = CompilerUtils::sizeOnStack(_function.returnParameters());
- unsigned const c_localVariablesSize = CompilerUtils::sizeOnStack(_function.localVariables());
vector<int> stackLayout;
stackLayout.push_back(c_returnValuesSize); // target of return address
stackLayout += vector<int>(c_argumentsSize, -1); // discard all arguments
for (unsigned i = 0; i < c_returnValuesSize; ++i)
stackLayout.push_back(i);
- stackLayout += vector<int>(c_localVariablesSize, -1);
if (stackLayout.size() > 17)
BOOST_THROW_EXCEPTION(
@@ -493,18 +488,23 @@ bool ContractCompiler::visit(FunctionDefinition const& _function)
m_context << swapInstruction(stackLayout.size() - stackLayout.back() - 1);
swap(stackLayout[stackLayout.back()], stackLayout.back());
}
- //@todo assert that everything is in place now
+ for (int i = 0; i < int(stackLayout.size()); ++i)
+ if (stackLayout[i] != i)
+ solAssert(false, "Invalid stack layout on cleanup.");
for (ASTPointer<VariableDeclaration const> const& variable: _function.parameters() + _function.returnParameters())
m_context.removeVariable(*variable);
- for (VariableDeclaration const* localVariable: _function.localVariables())
- m_context.removeVariable(*localVariable);
m_context.adjustStackOffset(-(int)c_returnValuesSize);
/// The constructor and the fallback function doesn't to jump out.
- if (!_function.isConstructor() && !_function.isFallback())
- m_context.appendJump(eth::AssemblyItem::JumpType::OutOfFunction);
+ if (!_function.isConstructor())
+ {
+ solAssert(m_context.numberOfLocalVariables() == 0, "");
+ if (!_function.isFallback())
+ m_context.appendJump(eth::AssemblyItem::JumpType::OutOfFunction);
+ }
+
return false;
}
@@ -669,14 +669,14 @@ bool ContractCompiler::visit(WhileStatement const& _whileStatement)
eth::AssemblyItem loopStart = m_context.newTag();
eth::AssemblyItem loopEnd = m_context.newTag();
- m_breakTags.push_back(loopEnd);
+ m_breakTags.push_back({loopEnd, m_context.stackHeight()});
m_context << loopStart;
if (_whileStatement.isDoWhile())
{
eth::AssemblyItem condition = m_context.newTag();
- m_continueTags.push_back(condition);
+ m_continueTags.push_back({condition, m_context.stackHeight()});
_whileStatement.body().accept(*this);
@@ -687,7 +687,7 @@ bool ContractCompiler::visit(WhileStatement const& _whileStatement)
}
else
{
- m_continueTags.push_back(loopStart);
+ m_continueTags.push_back({loopStart, m_context.stackHeight()});
compileExpression(_whileStatement.condition());
m_context << Instruction::ISZERO;
m_context.appendConditionalJumpTo(loopEnd);
@@ -712,12 +712,14 @@ bool ContractCompiler::visit(ForStatement const& _forStatement)
eth::AssemblyItem loopStart = m_context.newTag();
eth::AssemblyItem loopEnd = m_context.newTag();
eth::AssemblyItem loopNext = m_context.newTag();
- m_continueTags.push_back(loopNext);
- m_breakTags.push_back(loopEnd);
+
+ storeStackHeight(&_forStatement);
if (_forStatement.initializationExpression())
_forStatement.initializationExpression()->accept(*this);
+ m_breakTags.push_back({loopEnd, m_context.stackHeight()});
+ m_continueTags.push_back({loopNext, m_context.stackHeight()});
m_context << loopStart;
// if there is no terminating condition in for, default is to always be true
@@ -737,11 +739,16 @@ bool ContractCompiler::visit(ForStatement const& _forStatement)
_forStatement.loopExpression()->accept(*this);
m_context.appendJumpTo(loopStart);
+
m_context << loopEnd;
m_continueTags.pop_back();
m_breakTags.pop_back();
+ // For the case where no break/return is executed:
+ // loop initialization variables have to be freed
+ popScopedVariables(&_forStatement);
+
checker.check();
return false;
}
@@ -750,7 +757,7 @@ bool ContractCompiler::visit(Continue const& _continueStatement)
{
CompilerContext::LocationSetter locationSetter(m_context, _continueStatement);
solAssert(!m_continueTags.empty(), "");
- m_context.appendJumpTo(m_continueTags.back());
+ CompilerUtils(m_context).popAndJump(m_continueTags.back().second, m_continueTags.back().first);
return false;
}
@@ -758,7 +765,7 @@ bool ContractCompiler::visit(Break const& _breakStatement)
{
CompilerContext::LocationSetter locationSetter(m_context, _breakStatement);
solAssert(!m_breakTags.empty(), "");
- m_context.appendJumpTo(m_breakTags.back());
+ CompilerUtils(m_context).popAndJump(m_breakTags.back().second, m_breakTags.back().first);
return false;
}
@@ -784,10 +791,8 @@ bool ContractCompiler::visit(Return const& _return)
for (auto const& retVariable: boost::adaptors::reverse(returnParameters))
CompilerUtils(m_context).moveToStackVariable(*retVariable);
}
- for (unsigned i = 0; i < m_stackCleanupForReturn; ++i)
- m_context << Instruction::POP;
- m_context.appendJumpTo(m_returnTags.back());
- m_context.adjustStackOffset(m_stackCleanupForReturn);
+
+ CompilerUtils(m_context).popAndJump(m_returnTags.back().second, m_returnTags.back().first);
return false;
}
@@ -810,8 +815,15 @@ bool ContractCompiler::visit(EmitStatement const& _emit)
bool ContractCompiler::visit(VariableDeclarationStatement const& _variableDeclarationStatement)
{
- StackHeightChecker checker(m_context);
CompilerContext::LocationSetter locationSetter(m_context, _variableDeclarationStatement);
+
+ // Local variable slots are reserved when their declaration is visited,
+ // and freed in the end of their scope.
+ for (auto _decl: _variableDeclarationStatement.declarations())
+ if (_decl)
+ appendStackVariableInitialisation(*_decl);
+
+ StackHeightChecker checker(m_context);
if (Expression const* expression = _variableDeclarationStatement.initialValue())
{
CompilerUtils utils(m_context);
@@ -821,20 +833,19 @@ bool ContractCompiler::visit(VariableDeclarationStatement const& _variableDeclar
valueTypes = tupleType->components();
else
valueTypes = TypePointers{expression->annotation().type};
- auto const& assignments = _variableDeclarationStatement.annotation().assignments;
- solAssert(assignments.size() == valueTypes.size(), "");
- for (size_t i = 0; i < assignments.size(); ++i)
+ auto const& declarations = _variableDeclarationStatement.declarations();
+ solAssert(declarations.size() == valueTypes.size(), "");
+ for (size_t i = 0; i < declarations.size(); ++i)
{
- size_t j = assignments.size() - i - 1;
+ size_t j = declarations.size() - i - 1;
solAssert(!!valueTypes[j], "");
- VariableDeclaration const* varDecl = assignments[j];
- if (!varDecl)
- utils.popStackElement(*valueTypes[j]);
- else
+ if (VariableDeclaration const* varDecl = declarations[j].get())
{
utils.convertType(*valueTypes[j], *varDecl->annotation().type);
utils.moveToStackVariable(*varDecl);
}
+ else
+ utils.popStackElement(*valueTypes[j]);
}
}
checker.check();
@@ -861,6 +872,18 @@ bool ContractCompiler::visit(PlaceholderStatement const& _placeholderStatement)
return true;
}
+bool ContractCompiler::visit(Block const& _block)
+{
+ storeStackHeight(&_block);
+ return true;
+}
+
+void ContractCompiler::endVisit(Block const& _block)
+{
+ // Frees local variables declared in the scope of this block.
+ popScopedVariables(&_block);
+}
+
void ContractCompiler::appendMissingFunctions()
{
while (Declaration const* function = m_context.nextFunctionToCompile())
@@ -916,27 +939,19 @@ void ContractCompiler::appendModifierOrFunctionCode()
modifier.parameters()[i]->annotation().type
);
}
- for (VariableDeclaration const* localVariable: modifier.localVariables())
- {
- addedVariables.push_back(localVariable);
- appendStackVariableInitialisation(*localVariable);
- }
- stackSurplus =
- CompilerUtils::sizeOnStack(modifier.parameters()) +
- CompilerUtils::sizeOnStack(modifier.localVariables());
+ stackSurplus = CompilerUtils::sizeOnStack(modifier.parameters());
codeBlock = &modifier.body();
}
}
if (codeBlock)
{
- m_returnTags.push_back(m_context.newTag());
-
+ m_returnTags.push_back({m_context.newTag(), m_context.stackHeight()});
codeBlock->accept(*this);
solAssert(!m_returnTags.empty(), "");
- m_context << m_returnTags.back();
+ m_context << m_returnTags.back().first;
m_returnTags.pop_back();
CompilerUtils(m_context).popStackSlots(stackSurplus);
@@ -983,3 +998,20 @@ eth::AssemblyPointer ContractCompiler::cloneRuntime() const
a << u256(0x20) << u256(0) << Instruction::RETURN;
return make_shared<eth::Assembly>(a);
}
+
+void ContractCompiler::popScopedVariables(ASTNode const* _node)
+{
+ unsigned blockHeight = m_scopeStackHeight.at(m_modifierDepth).at(_node);
+ m_context.removeVariablesAboveStackHeight(blockHeight);
+ solAssert(m_context.stackHeight() >= blockHeight, "");
+ unsigned stackDiff = m_context.stackHeight() - blockHeight;
+ CompilerUtils(m_context).popStackSlots(stackDiff);
+ m_scopeStackHeight[m_modifierDepth].erase(_node);
+ if (m_scopeStackHeight[m_modifierDepth].size() == 0)
+ m_scopeStackHeight.erase(m_modifierDepth);
+}
+
+void ContractCompiler::storeStackHeight(ASTNode const* _node)
+{
+ m_scopeStackHeight[m_modifierDepth][_node] = m_context.stackHeight();
+}
diff --git a/libsolidity/codegen/ContractCompiler.h b/libsolidity/codegen/ContractCompiler.h
index 02a3452f..8516ec2c 100644
--- a/libsolidity/codegen/ContractCompiler.h
+++ b/libsolidity/codegen/ContractCompiler.h
@@ -109,6 +109,8 @@ private:
virtual bool visit(VariableDeclarationStatement const& _variableDeclarationStatement) override;
virtual bool visit(ExpressionStatement const& _expressionStatement) override;
virtual bool visit(PlaceholderStatement const&) override;
+ virtual bool visit(Block const& _block) override;
+ virtual void endVisit(Block const& _block) override;
/// Repeatedly visits all function which are referenced but which are not compiled yet.
void appendMissingFunctions();
@@ -123,19 +125,31 @@ private:
/// @returns the runtime assembly for clone contracts.
eth::AssemblyPointer cloneRuntime() const;
+ /// Frees the variables of a certain scope (to be used when leaving).
+ void popScopedVariables(ASTNode const* _node);
+
+ /// Sets the stack height for the visited loop.
+ void storeStackHeight(ASTNode const* _node);
+
bool const m_optimise;
/// Pointer to the runtime compiler in case this is a creation compiler.
ContractCompiler* m_runtimeCompiler = nullptr;
CompilerContext& m_context;
- std::vector<eth::AssemblyItem> m_breakTags; ///< tag to jump to for a "break" statement
- std::vector<eth::AssemblyItem> m_continueTags; ///< tag to jump to for a "continue" statement
- /// Tag to jump to for a "return" statement, needs to be stacked because of modifiers.
- std::vector<eth::AssemblyItem> m_returnTags;
+ /// Tag to jump to for a "break" statement and the stack height after freeing the local loop variables.
+ std::vector<std::pair<eth::AssemblyItem, unsigned>> m_breakTags;
+ /// Tag to jump to for a "continue" statement and the stack height after freeing the local loop variables.
+ std::vector<std::pair<eth::AssemblyItem, unsigned>> m_continueTags;
+ /// Tag to jump to for a "return" statement and the stack height after freeing the local function or modifier variables.
+ /// Needs to be stacked because of modifiers.
+ std::vector<std::pair<eth::AssemblyItem, unsigned>> m_returnTags;
unsigned m_modifierDepth = 0;
FunctionDefinition const* m_currentFunction = nullptr;
- unsigned m_stackCleanupForReturn = 0; ///< this number of stack elements need to be removed before jump to m_returnTag
+
// arguments for base constructors, filled in derived-to-base order
std::map<FunctionDefinition const*, ASTNode const*> const* m_baseArguments;
+
+ /// Stores the variables that were declared inside a specific scope, for each modifier depth.
+ std::map<unsigned, std::map<ASTNode const*, unsigned>> m_scopeStackHeight;
};
}
diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp
index 483faae4..4cec69c8 100644
--- a/libsolidity/codegen/ExpressionCompiler.cpp
+++ b/libsolidity/codegen/ExpressionCompiler.cpp
@@ -349,6 +349,10 @@ bool ExpressionCompiler::visit(UnaryOperation const& _unaryOperation)
case Token::Inc: // ++ (pre- or postfix)
case Token::Dec: // -- (pre- or postfix)
solAssert(!!m_currentLValue, "LValue not retrieved.");
+ solUnimplementedAssert(
+ _unaryOperation.annotation().type->category() != Type::Category::FixedPoint,
+ "Not yet implemented - FixedPointType."
+ );
m_currentLValue->retrieveValue(_unaryOperation.location());
if (!_unaryOperation.isPrefixOperation())
{
@@ -1647,12 +1651,12 @@ void ExpressionCompiler::appendOrdinaryBinaryOperatorCode(Token::Value _operator
void ExpressionCompiler::appendArithmeticOperatorCode(Token::Value _operator, Type const& _type)
{
- IntegerType const& type = dynamic_cast<IntegerType const&>(_type);
- bool const c_isSigned = type.isSigned();
-
if (_type.category() == Type::Category::FixedPoint)
solUnimplemented("Not yet implemented - FixedPointType.");
+ IntegerType const& type = dynamic_cast<IntegerType const&>(_type);
+ bool const c_isSigned = type.isSigned();
+
switch (_operator)
{
case Token::Add:
@@ -1810,15 +1814,11 @@ void ExpressionCompiler::appendExternalFunctionCall(
if (_functionType.bound())
utils().moveToStackTop(gasValueSize, _functionType.selfType()->sizeOnStack());
- bool const v050 = m_context.experimentalFeatureActive(ExperimentalFeature::V050);
auto funKind = _functionType.kind();
bool returnSuccessCondition = funKind == FunctionType::Kind::BareCall || funKind == FunctionType::Kind::BareCallCode || funKind == FunctionType::Kind::BareDelegateCall;
bool isCallCode = funKind == FunctionType::Kind::BareCallCode || funKind == FunctionType::Kind::CallCode;
bool isDelegateCall = funKind == FunctionType::Kind::BareDelegateCall || funKind == FunctionType::Kind::DelegateCall;
- bool useStaticCall =
- _functionType.stateMutability() <= StateMutability::View &&
- v050 &&
- m_context.evmVersion().hasStaticCall();
+ bool useStaticCall = _functionType.stateMutability() <= StateMutability::View && m_context.evmVersion().hasStaticCall();
bool haveReturndatacopy = m_context.evmVersion().supportsReturndata();
unsigned retSize = 0;
diff --git a/libsolidity/interface/Natspec.cpp b/libsolidity/interface/Natspec.cpp
index 7f7084ef..29a5b798 100644
--- a/libsolidity/interface/Natspec.cpp
+++ b/libsolidity/interface/Natspec.cpp
@@ -36,6 +36,10 @@ Json::Value Natspec::userDocumentation(ContractDefinition const& _contractDef)
Json::Value doc;
Json::Value methods(Json::objectValue);
+ string notice = extractDoc(_contractDef.annotation().docTags, "notice");
+ if (!notice.empty())
+ doc["notice"] = Json::Value(notice);
+
for (auto const& it: _contractDef.interfaceFunctions())
if (it.second->hasDeclaration())
if (auto const* f = dynamic_cast<FunctionDefinition const*>(&it.second->declaration()))
@@ -65,6 +69,9 @@ Json::Value Natspec::devDocumentation(ContractDefinition const& _contractDef)
auto title = extractDoc(_contractDef.annotation().docTags, "title");
if (!title.empty())
doc["title"] = title;
+ auto dev = extractDoc(_contractDef.annotation().docTags, "dev");
+ if (!dev.empty())
+ doc["details"] = Json::Value(dev);
for (auto const& it: _contractDef.interfaceFunctions())
{
diff --git a/test/compilationTests/MultiSigWallet/MultiSigWallet.sol b/test/compilationTests/MultiSigWallet/MultiSigWallet.sol
index 6b10f17e..c2a6c3ef 100644
--- a/test/compilationTests/MultiSigWallet/MultiSigWallet.sol
+++ b/test/compilationTests/MultiSigWallet/MultiSigWallet.sol
@@ -225,7 +225,7 @@ contract MultiSigWallet {
notExecuted(transactionId)
{
if (isConfirmed(transactionId)) {
- Transaction tx = transactions[transactionId];
+ Transaction storage tx = transactions[transactionId];
tx.executed = true;
if (tx.destination.call.value(tx.value)(tx.data))
emit Execution(transactionId);
diff --git a/test/compilationTests/MultiSigWallet/MultiSigWalletWithDailyLimit.sol b/test/compilationTests/MultiSigWallet/MultiSigWalletWithDailyLimit.sol
index 3a68f662..c1b1d7ea 100644
--- a/test/compilationTests/MultiSigWallet/MultiSigWalletWithDailyLimit.sol
+++ b/test/compilationTests/MultiSigWallet/MultiSigWalletWithDailyLimit.sol
@@ -42,7 +42,7 @@ contract MultiSigWalletWithDailyLimit is MultiSigWallet {
public
notExecuted(transactionId)
{
- Transaction tx = transactions[transactionId];
+ Transaction storage tx = transactions[transactionId];
bool confirmed = isConfirmed(transactionId);
if (confirmed || tx.data.length == 0 && isUnderLimit(tx.value)) {
tx.executed = true;
diff --git a/test/compilationTests/milestonetracker/MilestoneTracker.sol b/test/compilationTests/milestonetracker/MilestoneTracker.sol
index fc7008cd..bc182f9d 100644
--- a/test/compilationTests/milestonetracker/MilestoneTracker.sol
+++ b/test/compilationTests/milestonetracker/MilestoneTracker.sol
@@ -227,7 +227,7 @@ contract MilestoneTracker {
RLP.RLPItem memory itmProposal = itrProposals.next();
- Milestone milestone = milestones[milestones.length ++];
+ Milestone storage milestone = milestones[milestones.length ++];
if (!itmProposal.isList()) throw;
@@ -259,7 +259,7 @@ contract MilestoneTracker {
public campaignNotCanceled notChanging
{
if (_idMilestone >= milestones.length) throw;
- Milestone milestone = milestones[_idMilestone];
+ Milestone storage milestone = milestones[_idMilestone];
if ( (msg.sender != milestone.milestoneLeadLink)
&&(msg.sender != recipient))
throw;
@@ -277,7 +277,7 @@ contract MilestoneTracker {
public campaignNotCanceled notChanging
{
if (_idMilestone >= milestones.length) throw;
- Milestone milestone = milestones[_idMilestone];
+ Milestone storage milestone = milestones[_idMilestone];
if ((msg.sender != milestone.reviewer) ||
(milestone.status != MilestoneStatus.Completed)) throw;
@@ -292,7 +292,7 @@ contract MilestoneTracker {
public campaignNotCanceled notChanging
{
if (_idMilestone >= milestones.length) throw;
- Milestone milestone = milestones[_idMilestone];
+ Milestone storage milestone = milestones[_idMilestone];
if ((msg.sender != milestone.reviewer) ||
(milestone.status != MilestoneStatus.Completed)) throw;
@@ -307,7 +307,7 @@ contract MilestoneTracker {
function requestMilestonePayment(uint _idMilestone
) public campaignNotCanceled notChanging {
if (_idMilestone >= milestones.length) throw;
- Milestone milestone = milestones[_idMilestone];
+ Milestone storage milestone = milestones[_idMilestone];
if ( (msg.sender != milestone.milestoneLeadLink)
&&(msg.sender != recipient))
throw;
@@ -324,7 +324,7 @@ contract MilestoneTracker {
public onlyRecipient campaignNotCanceled notChanging
{
if (_idMilestone >= milestones.length) throw;
- Milestone milestone = milestones[_idMilestone];
+ Milestone storage milestone = milestones[_idMilestone];
if ((milestone.status != MilestoneStatus.AcceptedAndInProgress) &&
(milestone.status != MilestoneStatus.Completed))
throw;
@@ -339,7 +339,7 @@ contract MilestoneTracker {
function arbitrateApproveMilestone(uint _idMilestone
) public onlyArbitrator campaignNotCanceled notChanging {
if (_idMilestone >= milestones.length) throw;
- Milestone milestone = milestones[_idMilestone];
+ Milestone storage milestone = milestones[_idMilestone];
if ((milestone.status != MilestoneStatus.AcceptedAndInProgress) &&
(milestone.status != MilestoneStatus.Completed))
throw;
@@ -356,7 +356,7 @@ contract MilestoneTracker {
// @dev This internal function is executed when the milestone is paid out
function authorizePayment(uint _idMilestone) internal {
if (_idMilestone >= milestones.length) throw;
- Milestone milestone = milestones[_idMilestone];
+ Milestone storage milestone = milestones[_idMilestone];
// Recheck again to not pay twice
if (milestone.status == MilestoneStatus.AuthorizedForPayment) throw;
milestone.status = MilestoneStatus.AuthorizedForPayment;
diff --git a/test/compilationTests/zeppelin/token/VestedToken.sol b/test/compilationTests/zeppelin/token/VestedToken.sol
index 893a51db..48818c3f 100644
--- a/test/compilationTests/zeppelin/token/VestedToken.sol
+++ b/test/compilationTests/zeppelin/token/VestedToken.sol
@@ -74,7 +74,7 @@ contract VestedToken is StandardToken, LimitedTransferToken {
* @param _grantId The id of the token grant.
*/
function revokeTokenGrant(address _holder, uint256 _grantId) public {
- TokenGrant grant = grants[_holder][_grantId];
+ TokenGrant storage grant = grants[_holder][_grantId];
if (!grant.revokable) { // Check if grant was revokable
throw;
@@ -193,7 +193,7 @@ contract VestedToken is StandardToken, LimitedTransferToken {
* revokability, burnsOnRevoke, and vesting) plus the vested value at the current time.
*/
function tokenGrant(address _holder, uint256 _grantId) public view returns (address granter, uint256 value, uint256 vested, uint64 start, uint64 cliff, uint64 vesting, bool revokable, bool burnsOnRevoke) {
- TokenGrant grant = grants[_holder][_grantId];
+ TokenGrant storage grant = grants[_holder][_grantId];
granter = grant.granter;
value = grant.value;
diff --git a/test/contracts/AuctionRegistrar.cpp b/test/contracts/AuctionRegistrar.cpp
index 3d759aa0..0fc093e7 100644
--- a/test/contracts/AuctionRegistrar.cpp
+++ b/test/contracts/AuctionRegistrar.cpp
@@ -142,7 +142,7 @@ contract GlobalRegistrar is Registrar, AuctionSystem {
throw;
bid(_name, msg.sender, msg.value);
} else {
- Record record = m_toRecord[_name];
+ Record storage record = m_toRecord[_name];
if (record.owner != 0x0000000000000000000000000000000000000000)
throw;
m_toRecord[_name].owner = msg.sender;
diff --git a/test/contracts/FixedFeeRegistrar.cpp b/test/contracts/FixedFeeRegistrar.cpp
index 87f801b0..aebdb053 100644
--- a/test/contracts/FixedFeeRegistrar.cpp
+++ b/test/contracts/FixedFeeRegistrar.cpp
@@ -75,7 +75,7 @@ contract FixedFeeRegistrar is Registrar {
modifier onlyrecordowner(string _name) { if (m_record(_name).owner == msg.sender) _; }
function reserve(string _name) payable {
- Record rec = m_record(_name);
+ Record storage rec = m_record(_name);
if (rec.owner == 0x0000000000000000000000000000000000000000 && msg.value >= c_fee) {
rec.owner = msg.sender;
emit Changed(_name);
@@ -105,7 +105,7 @@ contract FixedFeeRegistrar is Registrar {
}
function record(string _name) view returns (address o_addr, address o_subRegistrar, bytes32 o_content, address o_owner) {
- Record rec = m_record(_name);
+ Record storage rec = m_record(_name);
o_addr = rec.addr;
o_subRegistrar = rec.subRegistrar;
o_content = rec.content;
diff --git a/test/contracts/Wallet.cpp b/test/contracts/Wallet.cpp
index b3a096a3..45fe5bbd 100644
--- a/test/contracts/Wallet.cpp
+++ b/test/contracts/Wallet.cpp
@@ -119,7 +119,7 @@ contract multiowned {
// make sure they're an owner
if (ownerIndex == 0) return;
uint ownerIndexBit = 2**ownerIndex;
- PendingState pending = m_pending[_operation];
+ PendingState storage pending = m_pending[_operation];
if (pending.ownersDone & ownerIndexBit > 0) {
pending.yetNeeded++;
pending.ownersDone -= ownerIndexBit;
@@ -178,7 +178,7 @@ contract multiowned {
}
function hasConfirmed(bytes32 _operation, address _owner) view returns (bool) {
- PendingState pending = m_pending[_operation];
+ PendingState storage pending = m_pending[_operation];
uint ownerIndex = m_ownerIndex[uint(_owner)];
// make sure they're an owner
@@ -201,7 +201,7 @@ contract multiowned {
// make sure they're an owner
if (ownerIndex == 0) return;
- PendingState pending = m_pending[_operation];
+ PendingState storage pending = m_pending[_operation];
// if we're not yet working on this operation, switch over and reset the confirmation status.
if (pending.yetNeeded == 0) {
// reset count of confirmations needed.
diff --git a/test/libsolidity/ASTJSON.cpp b/test/libsolidity/ASTJSON.cpp
index 03e74097..482b05e6 100644
--- a/test/libsolidity/ASTJSON.cpp
+++ b/test/libsolidity/ASTJSON.cpp
@@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE(long_type_name_binary_operation)
BOOST_AUTO_TEST_CASE(long_type_name_identifier)
{
CompilerStack c;
- c.addSource("a", "contract c { uint[] a; function f() public { uint[] b = a; } }");
+ c.addSource("a", "contract c { uint[] a; function f() public { uint[] storage b = a; } }");
c.setEVMVersion(dev::test::Options::get().evmVersion());
c.parseAndAnalyze();
map<string, unsigned> sourceIndices;
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 3cd3b9b7..bee83007 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -523,6 +523,96 @@ BOOST_AUTO_TEST_CASE(do_while_loop_continue)
ABI_CHECK(callContractFunction("f()"), encodeArgs(42));
}
+BOOST_AUTO_TEST_CASE(array_multiple_local_vars)
+{
+ char const* sourceCode = R"(
+ contract test {
+ function f(uint256[] seq) external pure returns (uint256) {
+ uint i = 0;
+ uint sum = 0;
+ while (i < seq.length)
+ {
+ uint idx = i;
+ if (idx >= 10) break;
+ uint x = seq[idx];
+ if (x >= 1000) {
+ uint n = i + 1;
+ i = n;
+ continue;
+ }
+ else {
+ uint y = sum + x;
+ sum = y;
+ }
+ if (sum >= 500) return sum;
+ i++;
+ }
+ return sum;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+
+ ABI_CHECK(callContractFunction("f(uint256[])", 32, 3, u256(1000), u256(1), u256(2)), encodeArgs(3));
+ ABI_CHECK(callContractFunction("f(uint256[])", 32, 3, u256(100), u256(500), u256(300)), encodeArgs(600));
+ ABI_CHECK(callContractFunction(
+ "f(uint256[])", 32, 11,
+ u256(1), u256(2), u256(3), u256(4), u256(5), u256(6), u256(7), u256(8), u256(9), u256(10), u256(111)
+ ), encodeArgs(55));
+}
+
+
+BOOST_AUTO_TEST_CASE(do_while_loop_multiple_local_vars)
+{
+ char const* sourceCode = R"(
+ contract test {
+ function f(uint x) public pure returns(uint r) {
+ uint i = 0;
+ do
+ {
+ uint z = x * 2;
+ if (z < 4) break;
+ else {
+ uint k = z + 1;
+ if (k < 8) {
+ x++;
+ continue;
+ }
+ }
+ if (z > 12) return 0;
+ x++;
+ i++;
+ } while (true);
+ return 42;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+
+ auto do_while = [](u256 n) -> u256
+ {
+ u256 i = 0;
+ do
+ {
+ u256 z = n * 2;
+ if (z < 4) break;
+ else {
+ u256 k = z + 1;
+ if (k < 8) {
+ n++;
+ continue;
+ }
+ }
+ if (z > 12) return 0;
+ n++;
+ i++;
+ } while (true);
+ return 42;
+ };
+
+ testContractAgainstCppOnRange("f(uint256)", do_while, 0, 12);
+}
+
BOOST_AUTO_TEST_CASE(nested_loops)
{
// tests that break and continue statements in nested loops jump to the correct place
@@ -574,6 +664,178 @@ BOOST_AUTO_TEST_CASE(nested_loops)
testContractAgainstCppOnRange("f(uint256)", nested_loops_cpp, 0, 12);
}
+BOOST_AUTO_TEST_CASE(nested_loops_multiple_local_vars)
+{
+ // tests that break and continue statements in nested loops jump to the correct place
+ // and free local variables properly
+ char const* sourceCode = R"(
+ contract test {
+ function f(uint x) returns(uint y) {
+ while (x > 0) {
+ uint z = x + 10;
+ uint k = z + 1;
+ if (k > 20) {
+ break;
+ uint p = 100;
+ k += p;
+ }
+ if (k > 15) {
+ x--;
+ continue;
+ uint t = 1000;
+ x += t;
+ }
+ while (k > 10) {
+ uint m = k - 1;
+ if (m == 10) return x;
+ return k;
+ uint h = 10000;
+ z += h;
+ }
+ x--;
+ break;
+ }
+ return x;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+
+ auto nested_loops_cpp = [](u256 n) -> u256
+ {
+ while (n > 0)
+ {
+ u256 z = n + 10;
+ u256 k = z + 1;
+ if (k > 20) break;
+ if (k > 15) {
+ n--;
+ continue;
+ }
+ while (k > 10)
+ {
+ u256 m = k - 1;
+ if (m == 10) return n;
+ return k;
+ }
+ n--;
+ break;
+ }
+
+ return n;
+ };
+
+ testContractAgainstCppOnRange("f(uint256)", nested_loops_cpp, 0, 12);
+}
+
+BOOST_AUTO_TEST_CASE(for_loop_multiple_local_vars)
+{
+ char const* sourceCode = R"(
+ contract test {
+ function f(uint x) public pure returns(uint r) {
+ for (uint i = 0; i < 12; i++)
+ {
+ uint z = x + 1;
+ if (z < 4) break;
+ else {
+ uint k = z * 2;
+ if (i + k < 10) {
+ x++;
+ continue;
+ }
+ }
+ if (z > 8) return 0;
+ x++;
+ }
+ return 42;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+
+ auto for_loop = [](u256 n) -> u256
+ {
+ for (u256 i = 0; i < 12; i++)
+ {
+ u256 z = n + 1;
+ if (z < 4) break;
+ else {
+ u256 k = z * 2;
+ if (i + k < 10) {
+ n++;
+ continue;
+ }
+ }
+ if (z > 8) return 0;
+ n++;
+ }
+ return 42;
+ };
+
+ testContractAgainstCppOnRange("f(uint256)", for_loop, 0, 12);
+}
+
+BOOST_AUTO_TEST_CASE(nested_for_loop_multiple_local_vars)
+{
+ char const* sourceCode = R"(
+ contract test {
+ function f(uint x) public pure returns(uint r) {
+ for (uint i = 0; i < 5; i++)
+ {
+ uint z = x + 1;
+ if (z < 3) {
+ break;
+ uint p = z + 2;
+ }
+ for (uint j = 0; j < 5; j++)
+ {
+ uint k = z * 2;
+ if (j + k < 8) {
+ x++;
+ continue;
+ uint t = z * 3;
+ }
+ x++;
+ if (x > 20) {
+ return 84;
+ uint h = x + 42;
+ }
+ }
+ if (x > 30) {
+ return 42;
+ uint b = 0xcafe;
+ }
+ }
+ return 42;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+
+ auto for_loop = [](u256 n) -> u256
+ {
+ for (u256 i = 0; i < 5; i++)
+ {
+ u256 z = n + 1;
+ if (z < 3) break;
+ for (u256 j = 0; j < 5; j++)
+ {
+ u256 k = z * 2;
+ if (j + k < 8) {
+ n++;
+ continue;
+ }
+ n++;
+ if (n > 20) return 84;
+ }
+ if (n > 30) return 42;
+ }
+ return 42;
+ };
+
+ testContractAgainstCppOnRange("f(uint256)", for_loop, 0, 12);
+}
+
BOOST_AUTO_TEST_CASE(for_loop)
{
char const* sourceCode = R"(
@@ -1273,7 +1535,7 @@ BOOST_AUTO_TEST_CASE(struct_reference)
function set() public {
data.z = 2;
mapping(uint8 => s2) map = data.recursive;
- s2 inner = map[0];
+ s2 storage inner = map[0];
inner.z = 3;
inner.recursive[0].z = inner.recursive[1].z + 1;
}
@@ -6112,7 +6374,7 @@ BOOST_AUTO_TEST_CASE(struct_assign_reference_to_struct)
}
function assign() public returns (uint ret_local, uint ret_global, uint ret_global3, uint ret_global1)
{
- testStruct x = data1; //x is a reference data1.m_value == 2 as well as x.m_value = 2
+ testStruct storage x = data1; //x is a reference data1.m_value == 2 as well as x.m_value = 2
data2 = data1; // should copy data. data2.m_value == 2
ret_local = x.m_value; // = 2
@@ -6144,7 +6406,7 @@ BOOST_AUTO_TEST_CASE(struct_delete_member)
}
function deleteMember() public returns (uint ret_value)
{
- testStruct x = data1; //should not copy the data. data1.m_value == 2 but x.m_value = 0
+ testStruct storage x = data1; //should not copy the data. data1.m_value == 2 but x.m_value = 0
x.m_value = 4;
delete x.m_value;
ret_value = data1.m_value;
@@ -7829,17 +8091,36 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration)
function g() public returns (uint a, uint b, uint c) {
a = 1; b = 2; c = 3;
}
- function f() public returns (bool) {
+ function h() public returns (uint a, uint b, uint c, uint d) {
+ a = 1; b = 2; c = 3; d = 4;
+ }
+ function f1() public returns (bool) {
(uint x, uint y, uint z) = g();
if (x != 1 || y != 2 || z != 3) return false;
(, uint a,) = g();
if (a != 2) return false;
- (uint b,) = g();
+ (uint b, , ) = g();
if (b != 1) return false;
- (, uint c) = g();
+ (, , uint c) = g();
if (c != 3) return false;
return true;
}
+ function f2() public returns (bool) {
+ (uint a1, , uint a3, ) = h();
+ if (a1 != 1 || a3 != 3) return false;
+ (uint b1, uint b2, , ) = h();
+ if (b1 != 1 || b2 != 2) return false;
+ (, uint c2, uint c3, ) = h();
+ if (c2 != 2 || c3 != 3) return false;
+ (, , uint d3, uint d4) = h();
+ if (d3 != 3 || d4 != 4) return false;
+ (uint e1, , uint e3, uint e4) = h();
+ if (e1 != 1 || e3 != 3 || e4 != 4) return false;
+ return true;
+ }
+ function f() public returns (bool) {
+ return f1() && f2();
+ }
}
)";
compileAndRun(sourceCode);
@@ -8611,7 +8892,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_storage_access_via_pointer)
Data public a;
uint public separator2;
function f() public returns (bool) {
- Data x = a;
+ Data storage x = a;
uint off;
assembly {
sstore(x_slot, 7)
@@ -9232,7 +9513,9 @@ BOOST_AUTO_TEST_CASE(break_in_modifier)
}
}
function f() run {
- x++;
+ uint k = x;
+ uint t = k + 1;
+ x = t;
}
}
)";
@@ -9242,6 +9525,54 @@ BOOST_AUTO_TEST_CASE(break_in_modifier)
ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(1)));
}
+BOOST_AUTO_TEST_CASE(continue_in_modifier)
+{
+ char const* sourceCode = R"(
+ contract C {
+ uint public x;
+ modifier run() {
+ for (uint i = 0; i < 10; i++) {
+ if (i % 2 == 1) continue;
+ _;
+ }
+ }
+ function f() run {
+ uint k = x;
+ uint t = k + 1;
+ x = t;
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+ ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(0)));
+ ABI_CHECK(callContractFunction("f()"), encodeArgs());
+ ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(5)));
+}
+
+BOOST_AUTO_TEST_CASE(return_in_modifier)
+{
+ char const* sourceCode = R"(
+ contract C {
+ uint public x;
+ modifier run() {
+ for (uint i = 1; i < 10; i++) {
+ if (i == 5) return;
+ _;
+ }
+ }
+ function f() run {
+ uint k = x;
+ uint t = k + 1;
+ x = t;
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+ ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(0)));
+ ABI_CHECK(callContractFunction("f()"), encodeArgs());
+ ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(4)));
+}
+
BOOST_AUTO_TEST_CASE(stacked_return_with_modifiers)
{
char const* sourceCode = R"(
@@ -9254,7 +9585,9 @@ BOOST_AUTO_TEST_CASE(stacked_return_with_modifiers)
}
}
function f() run {
- x++;
+ uint k = x;
+ uint t = k + 1;
+ x = t;
}
}
)";
@@ -12173,7 +12506,6 @@ BOOST_AUTO_TEST_CASE(abi_encode_call)
BOOST_AUTO_TEST_CASE(staticcall_for_view_and_pure)
{
char const* sourceCode = R"(
- pragma experimental "v0.5.0";
contract C {
uint x;
function f() public returns (uint) {
@@ -12408,6 +12740,43 @@ BOOST_AUTO_TEST_CASE(senders_balance)
BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(27)));
}
+BOOST_AUTO_TEST_CASE(write_storage_external)
+{
+ char const* sourceCode = R"(
+ contract C {
+ uint public x;
+ function f(uint y) public payable {
+ x = y;
+ }
+ function g(uint y) external {
+ x = y;
+ }
+ function h() public {
+ this.g(12);
+ }
+ }
+ contract D {
+ C c = new C();
+ function f() public payable returns (uint) {
+ c.g(3);
+ return c.x();
+ }
+ function g() public returns (uint) {
+ c.g(8);
+ return c.x();
+ }
+ function h() public returns (uint) {
+ c.h();
+ return c.x();
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "D");
+ ABI_CHECK(callContractFunction("f()"), encodeArgs(3));
+ ABI_CHECK(callContractFunction("g()"), encodeArgs(8));
+ ABI_CHECK(callContractFunction("h()"), encodeArgs(12));
+}
+
BOOST_AUTO_TEST_SUITE_END()
}
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index e6d93b36..6ae9d8f9 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -208,7 +208,7 @@ BOOST_AUTO_TEST_CASE(external_structs)
struct X { bytes32 x; Test t; Simple[] s; }
function f(ActionChoices, uint, Simple) external {}
function g(Test, Nested) external {}
- function h(function(Nested) external returns (uint)[]) external {}
+ function h(function(Nested memory) external returns (uint)[]) external {}
function i(Nested[]) external {}
}
)";
@@ -236,7 +236,7 @@ BOOST_AUTO_TEST_CASE(external_structs_in_libraries)
struct X { bytes32 x; Test t; Simple[] s; }
function f(ActionChoices, uint, Simple) external {}
function g(Test, Nested) external {}
- function h(function(Nested) external returns (uint)[]) external {}
+ function h(function(Nested memory) external returns (uint)[]) external {}
function i(Nested[]) external {}
}
)";
diff --git a/test/libsolidity/SolidityOptimizer.cpp b/test/libsolidity/SolidityOptimizer.cpp
index a144068d..764550eb 100644
--- a/test/libsolidity/SolidityOptimizer.cpp
+++ b/test/libsolidity/SolidityOptimizer.cpp
@@ -518,8 +518,8 @@ BOOST_AUTO_TEST_CASE(inconsistency)
// Called with params: containerIndex=0, valueIndex=0
function levelIII(uint containerIndex, uint valueIndex) private {
- Container container = containers[containerIndex];
- Value value = container.values[valueIndex];
+ Container storage container = containers[containerIndex];
+ Value storage value = container.values[valueIndex];
debug = container.valueIndices[value.number];
}
function levelII() private {
@@ -530,7 +530,7 @@ BOOST_AUTO_TEST_CASE(inconsistency)
function trigger() public returns (uint) {
containers.length++;
- Container container = containers[0];
+ Container storage container = containers[0];
container.values.push(Value({
badnum: 9000,
diff --git a/test/libsolidity/syntaxTests/dataLocations/variable_declaration_location_specifier_test_reference_type.sol b/test/libsolidity/syntaxTests/dataLocations/variable_declaration_location_specifier_test_reference_type.sol
index bd011f2d..0fbad155 100644
--- a/test/libsolidity/syntaxTests/dataLocations/variable_declaration_location_specifier_test_reference_type.sol
+++ b/test/libsolidity/syntaxTests/dataLocations/variable_declaration_location_specifier_test_reference_type.sol
@@ -4,11 +4,10 @@ contract test {
function f() public {
uint[] storage s1 = a;
uint[] memory s2 = new uint[](42);
- uint[] s3 = b;
+ uint[] storage s3 = b;
s1.push(42);
s2[3] = 12;
s3.push(42);
}
}
// ----
-// Warning: (147-156): Variable is declared as a storage pointer. Use an explicit "storage" keyword to silence this warning.
diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/differentNumberOfComponents.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/differentNumberOfComponents.sol
new file mode 100644
index 00000000..3b05a54c
--- /dev/null
+++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/differentNumberOfComponents.sol
@@ -0,0 +1,25 @@
+contract C {
+ function f() public {
+ uint a = (1,2);
+ uint b = (1,2,3);
+ uint c = (1,2,3,4);
+ }
+ function g() public {
+ (uint a1, uint b1, uint c1, uint d1) = 1;
+ (uint a2, uint b2, uint c2) = 1;
+ (uint a3, uint b3) = 1;
+ }
+ function h() public {
+ (uint a1, uint b1, uint c1, uint d1) = (1,2,3);
+ (uint a2, uint b2, uint c2) = (1,2,3,4);
+ }
+}
+// ----
+// TypeError: (47-61): Different number of components on the left hand side (1) than on the right hand side (2).
+// TypeError: (71-87): Different number of components on the left hand side (1) than on the right hand side (3).
+// TypeError: (97-115): Different number of components on the left hand side (1) than on the right hand side (4).
+// TypeError: (157-197): Different number of components on the left hand side (4) than on the right hand side (1).
+// TypeError: (207-238): Different number of components on the left hand side (3) than on the right hand side (1).
+// TypeError: (248-270): Different number of components on the left hand side (2) than on the right hand side (1).
+// TypeError: (312-358): Different number of components on the left hand side (4) than on the right hand side (3).
+// TypeError: (368-407): Different number of components on the left hand side (3) than on the right hand side (4).
diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/differentNumberOfComponentsFromReturn.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/differentNumberOfComponentsFromReturn.sol
new file mode 100644
index 00000000..7b556350
--- /dev/null
+++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/differentNumberOfComponentsFromReturn.sol
@@ -0,0 +1,29 @@
+contract C {
+ function f() public {
+ uint a = two();
+ uint b = three();
+ uint c = four();
+ }
+ function g() public {
+ (uint a1, uint b1, uint c1, uint d1) = one();
+ (uint a2, uint b2, uint c2) = one();
+ (uint a3, uint b3) = one();
+ }
+ function h() public {
+ (uint a1, uint b1, uint c1, uint d1) = three();
+ (uint a2, uint b2, uint c2) = four();
+ }
+ function one() public pure returns (uint);
+ function two() public pure returns (uint, uint);
+ function three() public pure returns (uint, uint, uint);
+ function four() public pure returns (uint, uint, uint, uint);
+}
+// ----
+// TypeError: (47-61): Different number of components on the left hand side (1) than on the right hand side (2).
+// TypeError: (71-87): Different number of components on the left hand side (1) than on the right hand side (3).
+// TypeError: (97-112): Different number of components on the left hand side (1) than on the right hand side (4).
+// TypeError: (154-198): Different number of components on the left hand side (4) than on the right hand side (1).
+// TypeError: (208-243): Different number of components on the left hand side (3) than on the right hand side (1).
+// TypeError: (253-279): Different number of components on the left hand side (2) than on the right hand side (1).
+// TypeError: (321-367): Different number of components on the left hand side (4) than on the right hand side (3).
+// TypeError: (377-413): Different number of components on the left hand side (3) than on the right hand side (4).
diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/disallowWildcards.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/disallowWildcards.sol
new file mode 100644
index 00000000..b500823d
--- /dev/null
+++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/disallowWildcards.sol
@@ -0,0 +1,24 @@
+contract C {
+ function fn() public pure {
+ (uint a,) = (1,2,3);
+ (,uint b) = (1,2,3);
+ (,uint c,) = (1,2,3,4,5);
+ (uint d, uint e,) = (1,2,3,4);
+ (,uint f, uint g) = (1,2,3,4);
+ (,uint h, uint i,) = (1,2,3);
+ (uint j,) = 1;
+ (,uint k) = 1;
+ (,uint l,) = 1;
+ a;b;c;d;e;f;g;h;i;j;k;l;
+ }
+}
+// ----
+// TypeError: (53-72): Different number of components on the left hand side (2) than on the right hand side (3).
+// TypeError: (82-101): Different number of components on the left hand side (2) than on the right hand side (3).
+// TypeError: (111-135): Different number of components on the left hand side (3) than on the right hand side (5).
+// TypeError: (145-174): Different number of components on the left hand side (3) than on the right hand side (4).
+// TypeError: (184-213): Different number of components on the left hand side (3) than on the right hand side (4).
+// TypeError: (223-251): Different number of components on the left hand side (4) than on the right hand side (3).
+// TypeError: (261-274): Different number of components on the left hand side (2) than on the right hand side (1).
+// TypeError: (284-297): Different number of components on the left hand side (2) than on the right hand side (1).
+// TypeError: (307-321): Different number of components on the left hand side (3) than on the right hand side (1).
diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/disallowWildcardsFromReturn.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/disallowWildcardsFromReturn.sol
new file mode 100644
index 00000000..3224a182
--- /dev/null
+++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/disallowWildcardsFromReturn.sol
@@ -0,0 +1,31 @@
+contract C {
+ function fn() public pure {
+ (uint a,) = three();
+ (,uint b) = three();
+ (,uint c,) = five();
+ (uint d, uint e,) = four();
+ (,uint f, uint g) = four();
+ (,uint h, uint i,) = three();
+ (uint j,) = one();
+ (,uint k) = one();
+ (,uint l,) = one();
+ (,uint m, uint n,) = five();
+ a;b;c;d;e;f;g;h;i;j;k;l;m;n;
+ }
+ function one() public pure returns (uint);
+ function two() public pure returns (uint, uint);
+ function three() public pure returns (uint, uint, uint);
+ function four() public pure returns (uint, uint, uint, uint);
+ function five() public pure returns (uint, uint, uint, uint, uint);
+}
+// ----
+// TypeError: (53-72): Different number of components on the left hand side (2) than on the right hand side (3).
+// TypeError: (82-101): Different number of components on the left hand side (2) than on the right hand side (3).
+// TypeError: (111-130): Different number of components on the left hand side (3) than on the right hand side (5).
+// TypeError: (140-166): Different number of components on the left hand side (3) than on the right hand side (4).
+// TypeError: (176-202): Different number of components on the left hand side (3) than on the right hand side (4).
+// TypeError: (212-240): Different number of components on the left hand side (4) than on the right hand side (3).
+// TypeError: (250-267): Different number of components on the left hand side (2) than on the right hand side (1).
+// TypeError: (277-294): Different number of components on the left hand side (2) than on the right hand side (1).
+// TypeError: (304-322): Different number of components on the left hand side (3) than on the right hand side (1).
+// TypeError: (332-359): Different number of components on the left hand side (4) than on the right hand side (5).
diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationComplex.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationComplex.sol
index a3ce6a74..ba6e9916 100644
--- a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationComplex.sol
+++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationComplex.sol
@@ -2,10 +2,10 @@ contract D {
struct S { uint a; uint b; }
}
contract C {
- function f() internal returns (uint, uint, uint, D.S[20] storage, uint) {
- (,,,D.S[10*2] storage x,) = f();
+ function f() internal pure {
+ (,,,D.S[10*2] storage x,) = g();
x;
}
-}
+ function g() internal pure returns (uint, uint, uint, D.S[20] storage x, uint) { x = x; }
+}
// ----
-// Warning: (110-117): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationEmpty.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationEmpty.sol
new file mode 100644
index 00000000..9618958e
--- /dev/null
+++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationEmpty.sol
@@ -0,0 +1,11 @@
+contract C {
+ function f() public pure {
+ (uint a, uint b) = f();
+ (uint c) = f();
+ uint d = f();
+ }
+}
+// ----
+// TypeError: (52-74): Different number of components on the left hand side (2) than on the right hand side (0).
+// TypeError: (84-98): Different number of components on the left hand side (1) than on the right hand side (0).
+// TypeError: (108-120): Different number of components on the left hand side (1) than on the right hand side (0).
diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationSimple.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationSimple.sol
index 8e06322c..a2fcce18 100644
--- a/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationSimple.sol
+++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/multiVariableDeclarationSimple.sol
@@ -1,12 +1,12 @@
contract C {
- function f() internal returns (uint, uint, uint, uint) {
+ function f() internal pure returns (uint, uint, uint, uint) {
(uint a, uint b,,) = f();
a; b;
}
- function g() internal returns (bytes memory, string storage) {
- (bytes memory a, string storage b) = g();
+ function g() internal pure {
+ (bytes memory a, string storage b) = h();
a; b;
}
-}
+ function h() internal pure returns (bytes memory, string storage s) { s = s; }
+}
// ----
-// Warning: (163-169): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/oneElementTuple.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/oneElementTuple.sol
new file mode 100644
index 00000000..562c7c0b
--- /dev/null
+++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/oneElementTuple.sol
@@ -0,0 +1,8 @@
+contract C {
+ function f() public {
+ (uint a,) = (1,);
+ a;
+ }
+}
+// ----
+// TypeError: (59-63): Tuple component cannot be empty.
diff --git a/test/libsolidity/syntaxTests/multiVariableDeclaration/sameNumberOfComponents.sol b/test/libsolidity/syntaxTests/multiVariableDeclaration/sameNumberOfComponents.sol
new file mode 100644
index 00000000..59eb34af
--- /dev/null
+++ b/test/libsolidity/syntaxTests/multiVariableDeclaration/sameNumberOfComponents.sol
@@ -0,0 +1,9 @@
+contract C {
+ function f() public pure {
+ (uint a1, uint b1, uint c1, uint d1) = (1,2,3,4);
+ (uint a2, uint b2, uint c2) = (1,2,3);
+ (uint a3, uint b3) = (1,2);
+ a1; b1; c1; d1; a2; b2; c2; a3; b3;
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/232_literal_string_to_storage_pointer.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/232_literal_string_to_storage_pointer.sol
index a586dc80..be57144e 100644
--- a/test/libsolidity/syntaxTests/nameAndTypeResolution/232_literal_string_to_storage_pointer.sol
+++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/232_literal_string_to_storage_pointer.sol
@@ -1,6 +1,5 @@
contract C {
- function f() public { string x = "abc"; }
+ function f() public { string storage x = "abc"; }
}
// ----
-// Warning: (39-47): Variable is declared as a storage pointer. Use an explicit "storage" keyword to silence this warning.
-// TypeError: (39-55): Type literal_string "abc" is not implicitly convertible to expected type string storage pointer.
+// TypeError: (39-63): Type literal_string "abc" is not implicitly convertible to expected type string storage pointer.
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/239_multi_variable_declaration_wildcards_fine.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/239_multi_variable_declaration_wildcards_fine.sol
deleted file mode 100644
index 0da5c7ee..00000000
--- a/test/libsolidity/syntaxTests/nameAndTypeResolution/239_multi_variable_declaration_wildcards_fine.sol
+++ /dev/null
@@ -1,19 +0,0 @@
-contract C {
- function three() public returns (uint, uint, uint);
- function two() public returns (uint, uint);
- function none() public;
- function f() public {
- (uint a,) = three();
- (uint b, uint c,) = two();
- (,uint d) = three();
- (,uint e, uint g) = two();
- var (,,) = three();
- var () = none();
- a;b;c;d;e;g;
- }
-}
-// ----
-// Warning: (179-198): Different number of components on the left hand side (2) than on the right hand side (3).
-// Warning: (208-233): Different number of components on the left hand side (3) than on the right hand side (2).
-// Warning: (243-262): Different number of components on the left hand side (2) than on the right hand side (3).
-// Warning: (272-297): Different number of components on the left hand side (3) than on the right hand side (2).
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/240_multi_variable_declaration_wildcards_fail_1.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/240_multi_variable_declaration_wildcards_fail_1.sol
deleted file mode 100644
index 0ccbb327..00000000
--- a/test/libsolidity/syntaxTests/nameAndTypeResolution/240_multi_variable_declaration_wildcards_fail_1.sol
+++ /dev/null
@@ -1,7 +0,0 @@
-contract C {
- function one() public returns (uint);
- function f() public { (uint a, uint b, ) = one(); }
-}
-// ----
-// Warning: (81-107): Different number of components on the left hand side (3) than on the right hand side (1).
-// TypeError: (81-107): Not enough components (1) in value to assign all variables (2).
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/241_multi_variable_declaration_wildcards_fail_2.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/241_multi_variable_declaration_wildcards_fail_2.sol
deleted file mode 100644
index 8d5de125..00000000
--- a/test/libsolidity/syntaxTests/nameAndTypeResolution/241_multi_variable_declaration_wildcards_fail_2.sol
+++ /dev/null
@@ -1,7 +0,0 @@
-contract C {
- function one() public returns (uint);
- function f() public { (uint a, , ) = one(); }
-}
-// ----
-// Warning: (81-101): Different number of components on the left hand side (3) than on the right hand side (1).
-// TypeError: (81-101): Not enough components (1) in value to assign all variables (2).
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/242_multi_variable_declaration_wildcards_fail_3.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/242_multi_variable_declaration_wildcards_fail_3.sol
deleted file mode 100644
index 993df9b9..00000000
--- a/test/libsolidity/syntaxTests/nameAndTypeResolution/242_multi_variable_declaration_wildcards_fail_3.sol
+++ /dev/null
@@ -1,7 +0,0 @@
-contract C {
- function one() public returns (uint);
- function f() public { (, , uint a) = one(); }
-}
-// ----
-// Warning: (81-101): Different number of components on the left hand side (3) than on the right hand side (1).
-// TypeError: (81-101): Not enough components (1) in value to assign all variables (2).
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/243_multi_variable_declaration_wildcards_fail_4.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/243_multi_variable_declaration_wildcards_fail_4.sol
deleted file mode 100644
index 0697b789..00000000
--- a/test/libsolidity/syntaxTests/nameAndTypeResolution/243_multi_variable_declaration_wildcards_fail_4.sol
+++ /dev/null
@@ -1,7 +0,0 @@
-contract C {
- function one() public returns (uint);
- function f() public { (, uint a, uint b) = one(); }
-}
-// ----
-// Warning: (81-107): Different number of components on the left hand side (3) than on the right hand side (1).
-// TypeError: (81-107): Not enough components (1) in value to assign all variables (2).
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/244_tuples.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/244_tuples.sol
index 95e8cf37..d18c115d 100644
--- a/test/libsolidity/syntaxTests/nameAndTypeResolution/244_tuples.sol
+++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/244_tuples.sol
@@ -1,13 +1,10 @@
contract C {
- function f() public {
+ function f() public pure {
uint a = (1);
- (uint b,) = uint8(1);
+ (uint b,) = (uint8(1),2);
(uint c, uint d) = (uint32(1), 2 + a);
- (uint e,) = (uint64(1), 2, b);
+ (uint e, ,) = (uint64(1), 2, b);
a;b;c;d;e;
}
}
// ----
-// Warning: (69-89): Different number of components on the left hand side (2) than on the right hand side (1).
-// Warning: (146-175): Different number of components on the left hand side (2) than on the right hand side (3).
-// Warning: (17-201): Function state mutability can be restricted to pure
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/246_multi_variable_declaration_wildcards_fail_5.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/246_multi_variable_declaration_wildcards_fail_5.sol
deleted file mode 100644
index 3d2d0705..00000000
--- a/test/libsolidity/syntaxTests/nameAndTypeResolution/246_multi_variable_declaration_wildcards_fail_5.sol
+++ /dev/null
@@ -1,6 +0,0 @@
-contract C {
- function one() public returns (uint);
- function f() public { var (,) = one(); }
-}
-// ----
-// TypeError: (81-96): Wildcard both at beginning and end of variable declaration list is only allowed if the number of components is equal.
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/247_multi_variable_declaration_wildcards_fail_6.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/247_multi_variable_declaration_wildcards_fail_6.sol
deleted file mode 100644
index cc5953db..00000000
--- a/test/libsolidity/syntaxTests/nameAndTypeResolution/247_multi_variable_declaration_wildcards_fail_6.sol
+++ /dev/null
@@ -1,7 +0,0 @@
-contract C {
- function two() public returns (uint, uint);
- function f() public { (uint a, uint b, uint c) = two(); }
-}
-// ----
-// Warning: (87-119): Different number of components on the left hand side (3) than on the right hand side (2).
-// TypeError: (87-119): Not enough components (2) in value to assign all variables (3).
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/250_member_access_parser_ambiguity.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/250_member_access_parser_ambiguity.sol
index f5252180..0ab3c198 100644
--- a/test/libsolidity/syntaxTests/nameAndTypeResolution/250_member_access_parser_ambiguity.sol
+++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/250_member_access_parser_ambiguity.sol
@@ -3,15 +3,14 @@ contract C {
struct S { uint a; uint b; uint[20][20][20] c; R d; }
S data;
function f() public {
- C.S x = data;
+ C.S storage x = data;
C.S memory y;
C.S[10] memory z;
C.S[10];
y.a = 2;
x.c[1][2][3] = 9;
x.d.y[2][2] = 3;
+ z;
}
}
// ----
-// Warning: (150-155): Variable is declared as a storage pointer. Use an explicit "storage" keyword to silence this warning.
-// Warning: (194-210): Unused local variable.
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/276_invalid_types_in_inline_array.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/276_invalid_types_in_inline_array.sol
index 6c8aabd5..03d7266a 100644
--- a/test/libsolidity/syntaxTests/nameAndTypeResolution/276_invalid_types_in_inline_array.sol
+++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/276_invalid_types_in_inline_array.sol
@@ -1,8 +1,7 @@
contract C {
function f() public {
- uint[3] x = [45, 'foo', true];
+ uint[3] memory x = [45, 'foo', true];
}
}
// ----
-// Warning: (47-56): Variable is declared as a storage pointer. Use an explicit "storage" keyword to silence this warning.
-// TypeError: (59-76): Unable to deduce common type for array elements.
+// TypeError: (66-83): Unable to deduce common type for array elements.
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/471_unspecified_storage_fail.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/471_unspecified_storage_fail.sol
new file mode 100644
index 00000000..6e401920
--- /dev/null
+++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/471_unspecified_storage_fail.sol
@@ -0,0 +1,13 @@
+contract C {
+ struct S { uint a; }
+ S m_x;
+ uint[] m_y;
+ function f() view public {
+ S x = m_x;
+ uint[] y = m_y;
+ x; y;
+ }
+}
+// ----
+// TypeError: (104-107): Data location must be specified as either "memory" or "storage".
+// TypeError: (123-131): Data location must be specified as either "memory" or "storage".
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/471_unspecified_storage_warn.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/471_unspecified_storage_warn.sol
deleted file mode 100644
index aa16a6b4..00000000
--- a/test/libsolidity/syntaxTests/nameAndTypeResolution/471_unspecified_storage_warn.sol
+++ /dev/null
@@ -1,10 +0,0 @@
-contract C {
- struct S { uint a; }
- S x;
- function f() view public {
- S y = x;
- y;
- }
-}
-// ----
-// Warning: (86-89): Variable is declared as a storage pointer. Use an explicit "storage" keyword to silence this warning.
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/472_unspecified_storage_v050.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/472_unspecified_storage_v050.sol
deleted file mode 100644
index 179c9931..00000000
--- a/test/libsolidity/syntaxTests/nameAndTypeResolution/472_unspecified_storage_v050.sol
+++ /dev/null
@@ -1,11 +0,0 @@
-pragma experimental "v0.5.0";
-contract C {
- struct S { uint a; }
- S x;
- function f() view public {
- S y = x;
- y;
- }
-}
-// ----
-// TypeError: (116-119): Data location must be specified as either "memory" or "storage".
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/481_explicit_literal_to_unspecified_string_assignment.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/481_explicit_literal_to_unspecified_string_assignment.sol
index 9801b831..ee56204a 100644
--- a/test/libsolidity/syntaxTests/nameAndTypeResolution/481_explicit_literal_to_unspecified_string_assignment.sol
+++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/481_explicit_literal_to_unspecified_string_assignment.sol
@@ -1,8 +1,7 @@
contract C {
function f() pure public {
- string x = "abc";
+ string storage x = "abc";
}
}
// ----
-// Warning: (52-60): Variable is declared as a storage pointer. Use an explicit "storage" keyword to silence this warning.
-// TypeError: (52-68): Type literal_string "abc" is not implicitly convertible to expected type string storage pointer.
+// TypeError: (52-76): Type literal_string "abc" is not implicitly convertible to expected type string storage pointer.
diff --git a/test/libsolidity/syntaxTests/parsing/arrays_in_expressions.sol b/test/libsolidity/syntaxTests/parsing/arrays_in_expressions.sol
index 2b35ffda..4c1f96e6 100644
--- a/test/libsolidity/syntaxTests/parsing/arrays_in_expressions.sol
+++ b/test/libsolidity/syntaxTests/parsing/arrays_in_expressions.sol
@@ -1,8 +1,6 @@
contract c {
- function f() public { c[10] a = 7; uint8[10 * 2] x; }
+ function f() public { c[10] storage a = 7; uint8[10 * 2] storage x; }
}
// ----
-// Warning: (39-46): Variable is declared as a storage pointer. Use an explicit "storage" keyword to silence this warning.
-// Warning: (52-67): Variable is declared as a storage pointer. Use an explicit "storage" keyword to silence this warning.
-// TypeError: (39-50): Type int_const 7 is not implicitly convertible to expected type contract c[10] storage pointer.
-// DeclarationError: (52-67): Uninitialized storage pointer. Did you mean '<type> memory x'?
+// TypeError: (39-58): Type int_const 7 is not implicitly convertible to expected type contract c[10] storage pointer.
+// DeclarationError: (60-83): Uninitialized storage pointer.
diff --git a/test/libsolidity/syntaxTests/parsing/multi_variable_declarations.sol b/test/libsolidity/syntaxTests/parsing/multi_variable_declarations.sol
index 1984ed36..56c2e280 100644
--- a/test/libsolidity/syntaxTests/parsing/multi_variable_declarations.sol
+++ b/test/libsolidity/syntaxTests/parsing/multi_variable_declarations.sol
@@ -2,8 +2,8 @@ contract C {
function f() pure public {
(uint a, uint b, uint c) = g();
(uint d) = 2;
- (, uint e) = 3;
- (uint h,) = 4;
+ (, uint e) = (3,4);
+ (uint h,) = (4,5);
(uint x,,) = g();
(, uint y,) = g();
a; b; c; d; e; h; x; y;
@@ -11,5 +11,3 @@ contract C {
function g() pure public returns (uint, uint, uint) {}
}
// ----
-// Warning: (93-107): Different number of components on the left hand side (2) than on the right hand side (1).
-// Warning: (111-124): Different number of components on the left hand side (2) than on the right hand side (1).
diff --git a/test/libsolidity/syntaxTests/parsing/tuples.sol b/test/libsolidity/syntaxTests/parsing/tuples.sol
index ca2f9d6b..875556e9 100644
--- a/test/libsolidity/syntaxTests/parsing/tuples.sol
+++ b/test/libsolidity/syntaxTests/parsing/tuples.sol
@@ -1,16 +1,11 @@
contract C {
- function f() public {
+ function f() public pure {
uint a = (1);
- (uint b,) = 1;
+ (uint b,) = (1,2);
(uint c, uint d) = (1, 2 + a);
- (uint e,) = (1, 2, b);
+ (uint e,) = (1, b);
(a) = 3;
+ a;b;c;d;e;
}
}
// ----
-// Warning: (54-67): Different number of components on the left hand side (2) than on the right hand side (1).
-// Warning: (104-125): Different number of components on the left hand side (2) than on the right hand side (3).
-// Warning: (72-78): Unused local variable.
-// Warning: (80-86): Unused local variable.
-// Warning: (105-111): Unused local variable.
-// Warning: (14-140): Function state mutability can be restricted to pure
diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_directly_recursive_dynamic_array.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_directly_recursive_dynamic_array.sol
new file mode 100644
index 00000000..d847f17c
--- /dev/null
+++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_directly_recursive_dynamic_array.sol
@@ -0,0 +1,7 @@
+contract Test {
+ struct MyStructName {
+ address addr;
+ MyStructName[] x;
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_directly_recursive_fixed_array.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_directly_recursive_fixed_array.sol
new file mode 100644
index 00000000..126dda4f
--- /dev/null
+++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_directly_recursive_fixed_array.sol
@@ -0,0 +1,8 @@
+contract Test {
+ struct MyStructName {
+ address addr;
+ MyStructName[1] x;
+ }
+}
+// ----
+// TypeError: (20-96): Recursive struct definition.
diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_complex.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_complex.sol
new file mode 100644
index 00000000..6d35a5d3
--- /dev/null
+++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_complex.sol
@@ -0,0 +1,18 @@
+contract Test {
+ struct MyStructName1 {
+ address addr;
+ uint256 count;
+ MyStructName4[1] x;
+ }
+ struct MyStructName2 {
+ MyStructName1 x;
+ }
+ struct MyStructName3 {
+ MyStructName2[1] x;
+ }
+ struct MyStructName4 {
+ MyStructName3 x;
+ }
+}
+// ----
+// TypeError: (20-121): Recursive struct definition.
diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_array1.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_array1.sol
new file mode 100644
index 00000000..10d7de2c
--- /dev/null
+++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_array1.sol
@@ -0,0 +1,11 @@
+contract Test {
+ struct MyStructName1 {
+ address addr;
+ uint256 count;
+ MyStructName2[] x;
+ }
+ struct MyStructName2 {
+ MyStructName1 x;
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_array2.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_array2.sol
new file mode 100644
index 00000000..f20510ca
--- /dev/null
+++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_array2.sol
@@ -0,0 +1,11 @@
+contract Test {
+ struct MyStructName1 {
+ address addr;
+ uint256 count;
+ MyStructName2 x;
+ }
+ struct MyStructName2 {
+ MyStructName1[] x;
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_array3.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_array3.sol
new file mode 100644
index 00000000..69747e71
--- /dev/null
+++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_array3.sol
@@ -0,0 +1,11 @@
+contract Test {
+ struct MyStructName1 {
+ address addr;
+ uint256 count;
+ MyStructName2[] x;
+ }
+ struct MyStructName2 {
+ MyStructName1[] x;
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_multi_array.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_multi_array.sol
new file mode 100644
index 00000000..b3507828
--- /dev/null
+++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_dynamic_multi_array.sol
@@ -0,0 +1,21 @@
+contract Test {
+ struct S1 {
+ S2[1][] x;
+ }
+ struct S2 {
+ S1 x;
+ }
+ struct T1 {
+ T2[][1] x;
+ }
+ struct T2 {
+ T1 x;
+ }
+ struct R1 {
+ R2[][] x;
+ }
+ struct R2 {
+ R1 x;
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_array1.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_array1.sol
new file mode 100644
index 00000000..2c0b90ec
--- /dev/null
+++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_array1.sol
@@ -0,0 +1,12 @@
+contract Test {
+ struct MyStructName1 {
+ address addr;
+ uint256 count;
+ MyStructName2[1] x;
+ }
+ struct MyStructName2 {
+ MyStructName1 x;
+ }
+}
+// ----
+// TypeError: (20-121): Recursive struct definition.
diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_array2.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_array2.sol
new file mode 100644
index 00000000..3178e569
--- /dev/null
+++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_array2.sol
@@ -0,0 +1,12 @@
+contract Test {
+ struct MyStructName1 {
+ address addr;
+ uint256 count;
+ MyStructName2 x;
+ }
+ struct MyStructName2 {
+ MyStructName1[1] x;
+ }
+}
+// ----
+// TypeError: (20-118): Recursive struct definition.
diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_array3.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_array3.sol
new file mode 100644
index 00000000..e34cf9bc
--- /dev/null
+++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_array3.sol
@@ -0,0 +1,12 @@
+contract Test {
+ struct MyStructName1 {
+ address addr;
+ uint256 count;
+ MyStructName2[1] x;
+ }
+ struct MyStructName2 {
+ MyStructName1[1] x;
+ }
+}
+// ----
+// TypeError: (20-121): Recursive struct definition.
diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_multi_array.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_multi_array.sol
new file mode 100644
index 00000000..ed659b6e
--- /dev/null
+++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive_fixed_multi_array.sol
@@ -0,0 +1,12 @@
+contract Test {
+ struct MyStructName1 {
+ address addr;
+ uint256 count;
+ MyStructName2[1][1] x;
+ }
+ struct MyStructName2 {
+ MyStructName1 x;
+ }
+}
+// ----
+// TypeError: (20-124): Recursive struct definition.
diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_not_really_recursive_array.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_not_really_recursive_array.sol
new file mode 100644
index 00000000..b2053b8a
--- /dev/null
+++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_not_really_recursive_array.sol
@@ -0,0 +1,4 @@
+contract Test {
+ struct S1 { uint a; }
+ struct S2 { S1[1] x; S1[1] y; }
+}
diff --git a/test/libsolidity/syntaxTests/tupleAssignments/warn_fill_vardecl.sol b/test/libsolidity/syntaxTests/tupleAssignments/warn_fill_vardecl.sol
deleted file mode 100644
index 23484567..00000000
--- a/test/libsolidity/syntaxTests/tupleAssignments/warn_fill_vardecl.sol
+++ /dev/null
@@ -1,8 +0,0 @@
-contract C {
- function f() public pure returns (uint, uint, uint, uint) {
- (uint a, uint b,) = f();
- a; b;
- }
-}
-// ----
-// Warning: (76-99): Different number of components on the left hand side (3) than on the right hand side (4).
diff --git a/test/libsolidity/syntaxTests/types/unnamed_tuple_decl.sol b/test/libsolidity/syntaxTests/types/unnamed_tuple_decl.sol
new file mode 100644
index 00000000..7ed92b58
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/unnamed_tuple_decl.sol
@@ -0,0 +1,18 @@
+pragma solidity ^0.4.20;
+
+contract C {
+ function f() internal pure {}
+ function g() internal pure returns (uint) { return 1; }
+ function h() internal pure returns (uint, uint) { return (1, 2); }
+
+ function test() internal pure {
+ var () = f();
+ var () = g();
+ var (,) = h();
+ }
+}
+
+// ----
+// SyntaxError: (249-261): The use of the "var" keyword is disallowed. The declaration part of the statement can be removed, since it is empty.
+// SyntaxError: (271-283): The use of the "var" keyword is disallowed. The declaration part of the statement can be removed, since it is empty.
+// SyntaxError: (293-306): The use of the "var" keyword is disallowed. The declaration part of the statement can be removed, since it is empty.