aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CODING_STYLE.md262
-rw-r--r--Changelog.md18
-rw-r--r--circle.yml16
-rw-r--r--docs/assembly.rst5
-rw-r--r--docs/contracts.rst50
-rw-r--r--docs/contributing.rst55
-rw-r--r--docs/control-structures.rst10
-rw-r--r--docs/introduction-to-smart-contracts.rst8
-rw-r--r--docs/miscellaneous.rst11
-rw-r--r--docs/solidity-by-example.rst9
-rw-r--r--docs/units-and-global-variables.rst7
-rw-r--r--libdevcore/Algorithms.h76
-rw-r--r--libdevcore/CommonIO.cpp20
-rw-r--r--libdevcore/CommonIO.h5
-rw-r--r--libevmasm/PeepholeOptimiser.cpp47
-rw-r--r--libevmasm/RuleList.h10
-rw-r--r--libjulia/optimiser/CommonSubexpressionEliminator.cpp48
-rw-r--r--libjulia/optimiser/CommonSubexpressionEliminator.h45
-rw-r--r--libsolidity/analysis/ConstantEvaluator.cpp6
-rw-r--r--libsolidity/analysis/ConstantEvaluator.h1
-rw-r--r--libsolidity/analysis/PostTypeChecker.cpp36
-rw-r--r--libsolidity/analysis/PostTypeChecker.h5
-rw-r--r--libsolidity/analysis/StaticAnalyzer.cpp14
-rw-r--r--libsolidity/analysis/StaticAnalyzer.h4
-rw-r--r--libsolidity/analysis/SyntaxChecker.cpp24
-rw-r--r--libsolidity/analysis/TypeChecker.cpp183
-rw-r--r--libsolidity/analysis/TypeChecker.h7
-rw-r--r--libsolidity/ast/AST.h25
-rw-r--r--libsolidity/ast/ASTAnnotations.h3
-rw-r--r--libsolidity/ast/ASTJsonConverter.cpp4
-rw-r--r--libsolidity/ast/AST_accept.h12
-rw-r--r--libsolidity/ast/Types.cpp38
-rw-r--r--libsolidity/ast/Types.h13
-rw-r--r--libsolidity/codegen/ArrayUtils.cpp49
-rw-r--r--libsolidity/codegen/ArrayUtils.h6
-rw-r--r--libsolidity/codegen/CompilerUtils.cpp30
-rw-r--r--libsolidity/codegen/CompilerUtils.h7
-rw-r--r--libsolidity/codegen/ContractCompiler.cpp46
-rw-r--r--libsolidity/codegen/ContractCompiler.h2
-rw-r--r--libsolidity/codegen/ExpressionCompiler.cpp29
-rw-r--r--libsolidity/formal/SymbolicBoolVariable.cpp6
-rw-r--r--libsolidity/formal/SymbolicBoolVariable.h3
-rw-r--r--libsolidity/formal/SymbolicIntVariable.cpp6
-rw-r--r--libsolidity/formal/SymbolicIntVariable.h3
-rw-r--r--libsolidity/formal/SymbolicVariable.cpp4
-rw-r--r--libsolidity/formal/SymbolicVariable.h8
-rw-r--r--libsolidity/interface/CompilerStack.cpp143
-rw-r--r--libsolidity/interface/ErrorReporter.cpp37
-rw-r--r--libsolidity/interface/ErrorReporter.h9
-rw-r--r--libsolidity/interface/GasEstimator.cpp9
-rw-r--r--libsolidity/parsing/Parser.cpp65
-rw-r--r--libsolidity/parsing/Parser.h7
-rw-r--r--libsolidity/parsing/Token.cpp2
-rwxr-xr-xscripts/cpp-ethereum/build.sh17
-rw-r--r--scripts/cpp-ethereum/eth_artful.docker7
-rw-r--r--scripts/cpp-ethereum/eth_trusty.docker13
-rwxr-xr-xscripts/tests.sh21
-rw-r--r--solc/CommandLineInterface.cpp20
-rw-r--r--std/StandardToken.sol4
-rw-r--r--std/owned.sol4
-rw-r--r--test/RPCSession.cpp6
-rw-r--r--test/libevmasm/Optimiser.cpp109
-rw-r--r--test/libjulia/CommonSubexpression.cpp102
-rw-r--r--test/libsolidity/AnalysisFramework.cpp28
-rw-r--r--test/libsolidity/AnalysisFramework.h7
-rw-r--r--test/libsolidity/FormattedScope.h2
-rw-r--r--test/libsolidity/GasMeter.cpp13
-rw-r--r--test/libsolidity/InlineAssembly.cpp2
-rw-r--r--test/libsolidity/JSONCompiler.cpp8
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp282
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp794
-rw-r--r--test/libsolidity/SolidityOptimizer.cpp28
-rw-r--r--test/libsolidity/SolidityParser.cpp20
-rw-r--r--test/libsolidity/SolidityTypes.cpp1
-rw-r--r--test/libsolidity/StandardCompiler.cpp6
-rw-r--r--test/libsolidity/SyntaxTest.cpp180
-rw-r--r--test/libsolidity/SyntaxTest.h36
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/array_length_cannot_be_constant_function_parameter.sol7
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_function.sol8
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_struct.sol7
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/can_be_recursive_constant.sol6
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/cannot_be_function.sol6
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/cannot_be_function_call.sol7
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/complex_cyclic_constant.sol10
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/const_cannot_be_fractional.sol6
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/constant_var.sol5
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/cyclic_constant.sol8
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/inline_array.sol5
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/invalid_expression_1.sol5
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/invalid_expression_2.sol5
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/invalid_expression_3.sol5
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/invalid_expression_4.sol5
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/invalid_expression_5.sol5
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/non_integer_constant_var.sol6
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/not_convertible_to_integer.sol5
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/parentheses.sol25
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/pure_functions.sol6
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/too_large.sol5
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/tuples.sol5
-rw-r--r--test/libsolidity/syntaxTests/constants/cyclic_dependency_1.sol5
-rw-r--r--test/libsolidity/syntaxTests/constants/cyclic_dependency_2.sol10
-rw-r--r--test/libsolidity/syntaxTests/constants/cyclic_dependency_3.sol11
-rw-r--r--test/libsolidity/syntaxTests/constants/cyclic_dependency_4.sol6
-rw-r--r--test/libsolidity/syntaxTests/double_stateVariable_declaration.sol2
-rw-r--r--test/libsolidity/syntaxTests/double_variable_declaration.sol2
-rw-r--r--test/libsolidity/syntaxTests/double_variable_declaration_050.sol6
-rw-r--r--test/libsolidity/syntaxTests/empty_struct.sol2
-rw-r--r--test/libsolidity/syntaxTests/empty_struct_050.sol2
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/call_value_on_non_payable_function_type.sol8
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/call_value_on_payable_function_type.sol6
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/delete_external_function_type_invalid.sol7
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/delete_function_type.sol17
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/delete_function_type_invalid.sol7
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/external_function_to_function_type_calldata_parameter.sol10
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/external_function_type_public_variable.sol11
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/external_function_type_returning_internal.sol5
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/external_function_type_taking_internal.sol5
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/external_function_type_to_address.sol5
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/external_function_type_to_uint.sol7
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/function_type.sol6
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/function_type_arrays.sol11
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/function_type_constructor.sol7
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/function_type_constructor_local.sol8
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/function_type_internal_public_variable.sol5
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/function_type_parameter.sol7
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/function_type_returned.sol5
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/function_type_variable_external_internal.sol6
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/function_types_internal_visibility_error.sol7
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/function_types_variable_visibility.sol9
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/internal_function_as_external_parameter.sol8
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/internal_function_as_external_parameter_in_library_external.sol6
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/internal_function_as_external_parameter_in_library_internal.sol4
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/internal_function_returned_from_public_function.sol7
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/internal_function_type_to_address.sol7
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/payable_internal_function_type.sol5
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/payable_internal_function_type_is_not_fatal.sol9
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/private_function_type.sol7
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/public_function_type.sol7
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/valid_function_type_variables.sol23
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/warn_function_type_parameters_with_names.sol5
-rw-r--r--test/libsolidity/syntaxTests/functionTypes/warn_function_type_return_parameters_with_names.sol5
-rw-r--r--test/libsolidity/syntaxTests/inheritance/allow_empty_duplicated_super_constructor_call.sol2
-rw-r--r--test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses.sol5
-rw-r--r--test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses_V050.sol9
-rw-r--r--test/libsolidity/syntaxTests/inheritance/base_arguments_multiple_inheritance.sol9
-rw-r--r--test/libsolidity/syntaxTests/inheritance/base_arguments_no_parentheses.sol5
-rw-r--r--test/libsolidity/syntaxTests/inheritance/disallow_modifier_style_without_parentheses.sol4
-rw-r--r--test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/ancestor.sol5
-rw-r--r--test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/ancestor_V050.sol7
-rw-r--r--test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base.sol4
-rw-r--r--test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_V050.sol6
-rw-r--r--test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi.sol7
-rw-r--r--test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor.sol6
-rw-r--r--test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor_modifier_style.sol6
-rw-r--r--test/libsolidity/syntaxTests/inheritance/too_few_base_arguments.sol8
-rw-r--r--test/libsolidity/syntaxTests/literal_comparisons.sol7
-rw-r--r--test/libsolidity/syntaxTests/modifiers/base_constructor_double_invocation.sol7
-rw-r--r--test/libsolidity/syntaxTests/modifiers/constructor_call_invalid_arg_count.sol9
-rw-r--r--test/libsolidity/syntaxTests/modifiers/function_modifier_double_invocation.sol4
-rw-r--r--test/libsolidity/syntaxTests/modifiers/function_modifier_invocation.sol5
-rw-r--r--test/libsolidity/syntaxTests/modifiers/function_modifier_invocation_local_variables.sol4
-rw-r--r--test/libsolidity/syntaxTests/modifiers/function_modifier_invocation_local_variables050.sol7
-rw-r--r--test/libsolidity/syntaxTests/modifiers/function_modifier_invocation_parameters.sol5
-rw-r--r--test/libsolidity/syntaxTests/modifiers/function_overrides_modifier.sol5
-rw-r--r--test/libsolidity/syntaxTests/modifiers/illegal_modifier_override.sol4
-rw-r--r--test/libsolidity/syntaxTests/modifiers/invalid_function_modifier_type.sol6
-rw-r--r--test/libsolidity/syntaxTests/modifiers/legal_modifier_override.sol2
-rw-r--r--test/libsolidity/syntaxTests/modifiers/modifier_overrides_function.sol5
-rw-r--r--test/libsolidity/syntaxTests/modifiers/modifier_returns_value.sol6
-rw-r--r--test/libsolidity/syntaxTests/modifiers/modifier_without_underscore.sol5
-rw-r--r--test/libsolidity/syntaxTests/modifiers/modifiers_on_abstract_functions_050.sol10
-rw-r--r--test/libsolidity/syntaxTests/modifiers/modifiers_on_abstract_functions_no_parser_error.sol13
-rw-r--r--test/libsolidity/syntaxTests/more_than_256_declarationerrors.sol524
-rw-r--r--test/libsolidity/syntaxTests/more_than_256_syntaxerrors.sol524
-rw-r--r--test/libsolidity/syntaxTests/parsing/missing_variable_name_in_declaration.sol5
-rw-r--r--test/libsolidity/syntaxTests/parsing/smoke_test.sol4
-rw-r--r--test/libsolidity/syntaxTests/scoping/double_function_declaration.sol2
-rw-r--r--test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope.sol2
-rw-r--r--test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_050.sol4
-rw-r--r--test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation.sol2
-rw-r--r--test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation_050.sol4
-rw-r--r--test/libsolidity/syntaxTests/scoping/name_shadowing.sol3
-rw-r--r--test/libsolidity/syntaxTests/scoping/scoping.sol2
-rw-r--r--test/libsolidity/syntaxTests/scoping/scoping_activation.sol2
-rw-r--r--test/libsolidity/syntaxTests/scoping/scoping_for3.sol2
-rw-r--r--test/libsolidity/syntaxTests/scoping/scoping_for_decl_in_body.sol2
-rw-r--r--test/libsolidity/syntaxTests/scoping/scoping_self_use_050.sol2
-rw-r--r--test/libsolidity/syntaxTests/smoke_test.sol2
-rw-r--r--test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol8
-rw-r--r--test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_special_types.sol10
-rw-r--r--test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs.sol6
-rw-r--r--test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_types.sol12
-rw-r--r--test/libsolidity/syntaxTests/structs/recursion/multi_struct_composition.sol15
-rw-r--r--test/libsolidity/syntaxTests/structs/recursion/parallel_structs.sol15
-rw-r--r--test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs.sol7
-rw-r--r--test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs2.sol7
-rw-r--r--test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs3.sol8
-rw-r--r--test/libsolidity/syntaxTests/structs/recursion/struct_definition_directly_recursive.sol8
-rw-r--r--test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive.sol12
-rw-r--r--test/libsolidity/syntaxTests/structs/recursion/struct_definition_not_really_recursive.sol4
-rw-r--r--test/libsolidity/syntaxTests/structs/recursion/struct_definition_recursion_via_mapping.sol7
-rw-r--r--test/libsolidity/syntaxTests/visibility/interface/function_default.sol4
-rw-r--r--test/libsolidity/syntaxTests/visibility/interface/function_default050.sol4
-rw-r--r--test/libsolidity/syntaxTests/visibility/interface/function_internal.sol2
-rw-r--r--test/libsolidity/syntaxTests/visibility/interface/function_private.sol2
-rw-r--r--test/libsolidity/syntaxTests/visibility/interface/function_public.sol2
-rw-r--r--test/libsolidity/syntaxTests/visibility/interface/function_public050.sol2
-rw-r--r--test/tools/isoltest.cpp128
208 files changed, 3922 insertions, 1322 deletions
diff --git a/CODING_STYLE.md b/CODING_STYLE.md
new file mode 100644
index 00000000..2cc9ac70
--- /dev/null
+++ b/CODING_STYLE.md
@@ -0,0 +1,262 @@
+0. Formatting
+
+GOLDEN RULE: Follow the style of the existing code when you make changes.
+
+a. Use tabs for leading indentation
+- tab stops are every 4 characters (only relevant for line length).
+- One indentation level -> exactly one byte (i.e. a tab character) in the source file.
+b. Line widths:
+- Lines should be at most 99 characters wide to make diff views readable and reduce merge conflicts.
+- Lines of comments should be formatted according to ease of viewing, but simplicity is to be preferred over beauty.
+c. Single-statement blocks should not have braces, unless required for clarity.
+d. Never place condition bodies on same line as condition.
+e. Space between keyword and opening parenthesis, but not following opening parenthesis or before final parenthesis.
+f. No spaces for unary operators, `->` or `.`.
+g. No space before ':' but one after it, except in the ternary operator: one on both sides.
+h. Add spaces around all other operators.
+i. Braces, when used, always have their own lines and are at same indentation level as "parent" scope.
+j. If lines are broken, a list of elements enclosed with parentheses (of any kind) and separated by a
+ separator (of any kind) are formatted such that there is exactly one element per line, followed by
+ the separator, the opening parenthesis is on the first line, followed by a line break and the closing
+ parenthesis is on a line of its own (unindented). See example below.
+
+(WRONG)
+if( a==b[ i ] ) { printf ("Hello\n"); }
+foo->bar(someLongVariableName,
+ anotherLongVariableName,
+ anotherLongVariableName,
+ anotherLongVariableName,
+ anotherLongVariableName);
+cout << "some very long string that contains completely irrelevant text that talks about this and that and contains the words \"lorem\" and \"ipsum\"" << endl;
+
+(RIGHT)
+if (a == b[i])
+ printf("Hello\n"); // NOTE spaces used instead of tab here for clarity - first byte should be '\t'.
+foo->bar(
+ someLongVariableName,
+ anotherLongVariableName,
+ anotherLongVariableName,
+ anotherLongVariableName,
+ anotherLongVariableName
+);
+cout <<
+ "some very long string that contains completely irrelevant " <<
+ "text that talks about this and that and contains the words " <<
+ "\"lorem\" and \"ipsum\"" <<
+ endl;
+
+
+
+1. Namespaces;
+
+a. No "using namespace" declarations in header files.
+b. All symbols should be declared in a namespace except for final applications.
+c. Use anonymous namespaces for helpers whose scope is a cpp file only.
+d. Preprocessor symbols should be prefixed with the namespace in all-caps and an underscore.
+
+(WRONG)
+#include <cassert>
+using namespace std;
+tuple<float, float> meanAndSigma(vector<float> const& _v);
+
+(CORRECT)
+#include <cassert>
+std::tuple<float, float> meanAndSigma(std::vector<float> const& _v);
+
+
+
+2. Preprocessor;
+
+a. File comment is always at top, and includes:
+- Copyright.
+- License (e.g. see COPYING).
+b. Never use #ifdef/#define/#endif file guards. Prefer #pragma once as first line below file comment.
+c. Prefer static const variable to value macros.
+d. Prefer inline constexpr functions to function macros.
+e. Split complex macro on multiple lines with '\'.
+
+
+
+3. Capitalization;
+
+GOLDEN RULE: Preprocessor: ALL_CAPS; C++: camelCase.
+
+a. Use camelCase for splitting words in names, except where obviously extending STL/boost functionality in which case follow those naming conventions.
+b. The following entities' first alpha is upper case:
+- Type names.
+- Template parameters.
+- Enum members.
+- static const variables that form an external API.
+c. All preprocessor symbols (macros, macro arguments) in full uppercase with underscore word separation.
+
+
+All other entities' first alpha is lower case.
+
+
+
+4. Variable prefixes:
+
+a. Leading underscore "_" to parameter names.
+- Exception: "o_parameterName" when it is used exclusively for output. See 6(f).
+- Exception: "io_parameterName" when it is used for both input and output. See 6(f).
+b. Leading "g_" to global (non-const) variables.
+c. Leading "s_" to static (non-const, non-global) variables.
+
+
+
+5. Assertions:
+
+- use `solAssert` and `solUnimplementedAssert` generously to check assumptions
+ that span across different parts of the code base, for example before dereferencing
+ a pointer.
+
+
+6. Declarations:
+
+a. {Typename} + {qualifiers} + {name}.
+b. Only one per line.
+c. Associate */& with type, not variable (at ends with parser, but more readable, and safe if in conjunction with (b)).
+d. Favour declarations close to use; don't habitually declare at top of scope ala C.
+e. Pass non-trivial parameters as const reference, unless the data is to be copied into the function, then either pass by const reference or by value and use std::move.
+f. If a function returns multiple values, use std::tuple (std::pair acceptable) or better introduce a struct type. Do not use */& arguments.
+g. Use parameters of pointer type only if ``nullptr`` is a valid argument, use references otherwise. Often, ``boost::optional`` is better suited than a raw pointer.
+h. Never use a macro where adequate non-preprocessor C++ can be written.
+i. Only use ``auto`` if the type is very long and rather irrelevant.
+j. Do not pass bools: prefer enumerations instead.
+k. Prefer enum class to straight enum.
+l. Always initialize POD variables, even if their value is overwritten later.
+
+
+(WRONG)
+const double d = 0;
+int i, j;
+char *s;
+float meanAndSigma(std::vector<float> _v, float* _sigma, bool _approximate);
+Derived* x(dynamic_cast<Derived*>(base));
+for (map<ComplexTypeOne, ComplexTypeTwo>::iterator i = l.begin(); i != l.end(); ++l) {}
+
+
+(CORRECT)
+enum class Accuracy
+{
+ Approximate,
+ Exact
+};
+struct MeanSigma
+{
+ float mean;
+ float standardDeviation;
+};
+double const d = 0;
+int i;
+int j;
+char* s;
+MeanAndSigma ms meanAndSigma(std::vector<float> const& _v, Accuracy _a);
+Derived* x = dynamic_cast<Derived*>(base);
+for (auto i = x->begin(); i != x->end(); ++i) {}
+
+
+7. Structs & classes
+
+a. Structs to be used when all members public and no virtual functions.
+- In this case, members should be named naturally and not prefixed with 'm_'
+b. Classes to be used in all other circumstances.
+
+
+
+8. Members:
+
+a. One member per line only.
+b. Private, non-static, non-const fields prefixed with m_.
+c. Avoid public fields, except in structs.
+d. Use override, final and const as much as possible.
+e. No implementations with the class declaration, except:
+- template or force-inline method (though prefer implementation at bottom of header file).
+- one-line implementation (in which case include it in same line as declaration).
+f. For a property 'foo'
+- Member: m_foo;
+- Getter: foo() [ also: for booleans, isFoo() ];
+- Setter: setFoo();
+
+
+
+9. Naming
+
+a. Avoid unpronouncable names
+b. Names should be shortened only if they are extremely common, but shortening should be generally avoided
+c. Avoid prefixes of initials (e.g. do not use IMyInterface, CMyImplementation)
+c. Find short, memorable & (at least semi-) descriptive names for commonly used classes or name-fragments.
+- A dictionary and thesaurus are your friends.
+- Spell correctly.
+- Think carefully about the class's purpose.
+- Imagine it as an isolated component to try to decontextualise it when considering its name.
+- Don't be trapped into naming it (purely) in terms of its implementation.
+
+
+
+10. Type-definitions
+
+a. Prefer 'using' to 'typedef'. e.g. using ints = std::vector<int>; rather than typedef std::vector<int> ints;
+b. Generally avoid shortening a standard form that already includes all important information:
+- e.g. stick to shared_ptr<X> rather than shortening to ptr<X>.
+c. Where there are exceptions to this (due to excessive use and clear meaning), note the change prominently and use it consistently.
+- e.g. using Guard = std::lock_guard<std::mutex>; ///< Guard is used throughout the codebase since it is clear in meaning and used commonly.
+d. In general expressions should be roughly as important/semantically meaningful as the space they occupy.
+e. Avoid introducing aliases for types unless they are very complicated. Consider the number of items a brain can keep track of at the same time.
+
+
+
+11. Commenting
+
+a. Comments should be doxygen-compilable, using @notation rather than \notation.
+b. Document the interface, not the implementation.
+- Documentation should be able to remain completely unchanged, even if the method is reimplemented.
+- Comment in terms of the method properties and intended alteration to class state (or what aspects of the state it reports).
+- Be careful to scrutinise documentation that extends only to intended purpose and usage.
+- Reject documentation that is simply an English transaction of the implementation.
+c. Avoid in-code comments. Instead, try to extract blocks of functionality into functions. This often already eliminates the need for an in-code comment.
+
+
+12. Include Headers
+
+Includes should go in increasing order of generality (libsolidity -> libevmasm -> libdevcore -> boost -> STL).
+The corresponding .h file should be the first include in the respective .cpp file.
+Insert empty lines between blocks of include files.
+
+Example:
+
+```
+#include <libsolidity/codegen/ExpressionCompiler.h>
+
+#include <libsolidity/ast/AST.h>
+#include <libsolidity/codegen/CompilerContext.h>
+#include <libsolidity/codegen/CompilerUtils.h>
+#include <libsolidity/codegen/LValue.h>
+
+#include <libevmasm/GasMeter.h>
+
+#include <libdevcore/Common.h>
+#include <libdevcore/SHA3.h>
+
+#include <boost/range/adaptor/reversed.hpp>
+#include <boost/algorithm/string/replace.hpp>
+
+#include <utility>
+#include <numeric>
+```
+
+See http://stackoverflow.com/questions/614302/c-header-order/614333#614333 for the reason: this makes it easier to find missing includes in header files.
+
+
+13. Recommended reading
+
+Herb Sutter and Bjarne Stroustrup
+- "C++ Core Guidelines" (https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md)
+
+Herb Sutter and Andrei Alexandrescu
+- "C++ Coding Standards: 101 Rules, Guidelines, and Best Practices"
+
+Scott Meyers
+- "Effective C++: 55 Specific Ways to Improve Your Programs and Designs (3rd Edition)"
+- "More Effective C++: 35 New Ways to Improve Your Programs and Designs"
+- "Effective Modern C++: 42 Specific Ways to Improve Your Use of C++11 and C++14"
diff --git a/Changelog.md b/Changelog.md
index 34c3b0e9..e2174cfd 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -2,11 +2,23 @@
Features:
* Code Generator: Initialize arrays without using ``msize()``.
+ * Code Generator: More specialized and thus optimized implementation for ``x.push(...)``
* Commandline interface: Error when missing or inaccessible file detected. Suppress it with the ``--ignore-missing`` flag.
+ * Constant Evaluator: Fix evaluation of single element tuples.
+ * General: Limit the number of errors output in a single run to 256.
* General: Support accessing dynamic return data in post-byzantium EVMs.
* Interfaces: Allow overriding external functions in interfaces with public in an implementing contract.
+ * Optimizer: Optimize ``SHL`` and ``SHR`` only involving constants (Constantinople only).
+ * Optimizer: Remove useless ``SWAP1`` instruction preceding a commutative instruction (such as ``ADD``, ``MUL``, etc).
+ * Optimizer: Replace comparison operators (``LT``, ``GT``, etc) with opposites if preceded by ``SWAP1``, e.g. ``SWAP1 LT`` is replaced with ``GT``.
* Optimizer: Optimize across ``mload`` if ``msize()`` is not used.
+ * Static Analyzer: Error on duplicated super constructor calls as experimental 0.5.0 feature.
* Syntax Checker: Issue warning for empty structs (or error as experimental 0.5.0 feature).
+ * Syntax Checker: Warn about modifiers on functions without implementation (this will turn into an error with version 0.5.0).
+ * Syntax Tests: Add source locations to syntax test expectations.
+ * General: Introduce new constructor syntax using the ``constructor`` keyword as experimental 0.5.0 feature.
+ * Inheritance: Error when using empty parentheses for base class constructors that require arguments as experimental 0.5.0 feature.
+ * Inheritance: Error when using no parentheses in modifier-style constructor calls as experimental 0.5.0 feature.
Bugfixes:
* Code Generator: Allow ``block.blockhash`` without being called.
@@ -15,12 +27,18 @@ Bugfixes:
* Code Generator: Bugfix in modifier lookup in libraries.
* Code Generator: Implement packed encoding of external function types.
* Code Generator: Treat empty base constructor argument list as not provided.
+ * Commandline interface: Fix error messages for imported files that do not exist.
* Commandline interface: Support ``--evm-version constantinople`` properly.
* DocString Parser: Fix error message for empty descriptions.
+ * Gas Estimator: Correctly ignore costs of fallback function for other functions.
+ * Parser: Fix parsing of getters for function type variables.
* Standard JSON: Support ``constantinople`` as ``evmVersion`` properly.
+ * Type Checker: Fix detection of recursive structs.
+ * Type Checker: Fix asymmetry bug when comparing with literal numbers.
* Type System: Improve error message when attempting to shift by a fractional amount.
* Type System: Make external library functions accessible.
* Type System: Prevent encoding of weird types.
+ * Static Analyzer: Fix non-deterministic order of unused variable warnings.
### 0.4.21 (2018-03-07)
diff --git a/circle.yml b/circle.yml
index c131962f..f97b619a 100644
--- a/circle.yml
+++ b/circle.yml
@@ -1,3 +1,10 @@
+defaults:
+ # The default for tags is to not run, so we have to explicitly match a filter.
+ - build_on_tags: &build_on_tags
+ filters:
+ tags:
+ only: /.*/
+
version: 2
jobs:
build_emscripten:
@@ -157,15 +164,18 @@ workflows:
version: 2
build_all:
jobs:
- - build_emscripten
+ - build_emscripten: *build_on_tags
- test_emscripten_solcjs:
+ <<: *build_on_tags
requires:
- build_emscripten
- test_emscripten_external:
+ <<: *build_on_tags
requires:
- build_emscripten
- - build_x86
+ - build_x86: *build_on_tags
- test_x86:
+ <<: *build_on_tags
requires:
- build_x86
- - docs
+ - docs: *build_on_tags
diff --git a/docs/assembly.rst b/docs/assembly.rst
index cf9bf840..705cd1b8 100644
--- a/docs/assembly.rst
+++ b/docs/assembly.rst
@@ -647,6 +647,11 @@ Solidity manages memory in a very simple way: There is a "free memory pointer"
at position ``0x40`` in memory. If you want to allocate memory, just use the memory
from that point on and update the pointer accordingly.
+The first 64 bytes of memory can be used as "scratch space" for short-term
+allocation. The 32 bytes after the free memory pointer (i.e. starting at ``0x60``)
+is meant to be zero permanently and is used as the initial value for
+empty dynamic memory arrays.
+
Elements in memory arrays in Solidity always occupy multiples of 32 bytes (yes, this is
even true for ``byte[]``, but not for ``bytes`` and ``string``). Multi-dimensional memory
arrays are pointers to memory arrays. The length of a dynamic array is stored at the
diff --git a/docs/contracts.rst b/docs/contracts.rst
index 8cc4f6b2..0dd9845c 100644
--- a/docs/contracts.rst
+++ b/docs/contracts.rst
@@ -40,7 +40,7 @@ This means that cyclic creation dependencies are impossible.
::
- pragma solidity ^0.4.16;
+ pragma solidity >0.4.21;
contract OwnedToken {
// TokenCreator is a contract type that is defined below.
@@ -52,7 +52,7 @@ This means that cyclic creation dependencies are impossible.
// This is the constructor which registers the
// creator and the assigned name.
- function OwnedToken(bytes32 _name) public {
+ constructor(bytes32 _name) public {
// State variables are accessed via their name
// and not via e.g. this.owner. This also applies
// to functions and especially in the constructors,
@@ -803,7 +803,7 @@ as topics. The event call above can be performed in the same way as
}
where the long hexadecimal number is equal to
-``keccak256("Deposit(address,hash256,uint256)")``, the signature of the event.
+``keccak256("Deposit(address,bytes32,uint256)")``, the signature of the event.
Additional Resources for Understanding Events
==============================================
@@ -976,8 +976,31 @@ virtual method lookup.
Constructors
============
-A constructor is an optional function with the same name as the contract which is executed upon contract creation.
-Constructor functions can be either ``public`` or ``internal``.
+A constructor is an optional function declared with the ``constructor`` keyword which is executed upon contract creation.
+Constructor functions can be either ``public`` or ``internal``. If there is no constructor, the contract will assume the
+default constructor: ``contructor() public {}``.
+
+
+::
+
+ pragma solidity >0.4.21;
+
+ contract A {
+ uint public a;
+
+ constructor(uint _a) internal {
+ a = _a;
+ }
+ }
+
+ contract B is A(1) {
+ constructor() public {}
+ }
+
+A constructor set as ``internal`` causes the contract to be marked as :ref:`abstract <abstract-contract>`.
+
+.. note ::
+ Prior to version 0.4.22, constructors were defined as functions with the same name as the contract. This syntax is now deprecated.
::
@@ -995,7 +1018,6 @@ Constructor functions can be either ``public`` or ``internal``.
function B() public {}
}
-A constructor set as ``internal`` causes the contract to be marked as :ref:`abstract <abstract-contract>`.
.. index:: ! base;constructor
@@ -1009,12 +1031,15 @@ the base constructors. This can be done in two ways::
contract Base {
uint x;
- function Base(uint _x) public { x = _x; }
+ constructor(uint _x) public { x = _x; }
}
- contract Derived is Base(7) {
- function Derived(uint _y) Base(_y * _y) public {
- }
+ contract Derived1 is Base(7) {
+ constructor(uint _y) public {}
+ }
+
+ contract Derived2 is Base {
+ constructor(uint _y) Base(_y * _y) public {}
}
One way is directly in the inheritance list (``is Base(7)``). The other is in
@@ -1024,8 +1049,9 @@ do it is more convenient if the constructor argument is a
constant and defines the behaviour of the contract or
describes it. The second way has to be used if the
constructor arguments of the base depend on those of the
-derived contract. If, as in this silly example, both places
-are used, the modifier-style argument takes precedence.
+derived contract. Arguments have to be given either in the
+inheritance list or in modifier-style in the derived constuctor.
+Specifying arguments in both places is an error.
.. index:: ! inheritance;multiple, ! linearization, ! C3 linearization
diff --git a/docs/contributing.rst b/docs/contributing.rst
index 1bcaed7c..6717a8b9 100644
--- a/docs/contributing.rst
+++ b/docs/contributing.rst
@@ -55,8 +55,8 @@ However, if you are making a larger change, please consult with the `Solidity De
focused on compiler and language development instead of language use) first.
-Finally, please make sure you respect the `coding standards
-<https://raw.githubusercontent.com/ethereum/cpp-ethereum/develop/CodingStandards.txt>`_
+Finally, please make sure you respect the `coding style
+<https://raw.githubusercontent.com/ethereum/solidity/develop/CODING_STYLE.md>`_
for this project. Also, even though we do CI testing, please test your code and
ensure that it builds locally before submitting a pull request.
@@ -170,6 +170,57 @@ and re-run the test. It will now pass again:
Please choose a name for the contract file, that is self-explainatory in the sense of what is been tested, e.g. ``double_variable_declaration.sol``.
Do not put more than one contract into a single file. ``isoltest`` is currently not able to recognize them individually.
+
+Running the Fuzzer via AFL
+==========================
+
+Fuzzing is a technique that runs programs on more or less random inputs to find exceptional execution
+states (segmentation faults, exceptions, etc). Modern fuzzers are clever and do a directed search
+inside the input. We have a specialized binary called ``solfuzzer`` which takes source code as input
+and fails whenever it encounters an internal compiler error, segmentation fault or similar, but
+does not fail if e.g. the code contains an error. This way, internal problems in the compiler
+can be found by fuzzing tools.
+
+We mainly use `AFL <http://lcamtuf.coredump.cx/afl/>`_ for fuzzing. You need to download and
+build AFL manually. Next, build Solidity (or just the ``solfuzzer`` binary) with AFL as your compiler:
+
+::
+
+ cd build
+ # if needed
+ make clean
+ cmake .. -DCMAKE_C_COMPILER=path/to/afl-gcc -DCMAKE_CXX_COMPILER=path/to/afl-g++
+ make solfuzzer
+
+Next, you need some example source files. This will make it much easer for the fuzzer
+to find errors. You can either copy some files from the syntax tests or extract test files
+from the documentation or the other tests:
+
+::
+
+ mkdir /tmp/test_cases
+ cd /tmp/test_cases
+ # extract from tests:
+ path/to/solidity/scripts/isolate_tests.py path/to/solidity/test/libsolidity/SolidityEndToEndTest.cpp
+ # extract from documentation:
+ path/to/solidity/scripts/isolate_tests.py path/to/solidity/docs docs
+
+The AFL documentation states that the corpus (the initial input files) should not be
+too large. The files themselves should not be larger than 1 kB and there should be
+at most one input file per functionality, so better start with a small number of
+input files. There is also a tool called ``afl-cmin`` that can trim input files
+that result in similar behaviour of the binary.
+
+Now run the fuzzer (the ``-m`` extends the size of memory to 60 MB):
+
+::
+
+ afl-fuzz -m 60 -i /tmp/test_cases -o /tmp/fuzzer_reports -- /path/to/solfuzzer
+
+The fuzzer will create source files that lead to failures in ``/tmp/fuzzer_reports``.
+Often it finds many similar source files that produce the same error. You can
+use the tool ``scripts/uniqueErrors.sh`` to filter out the unique errors.
+
Whiskers
========
diff --git a/docs/control-structures.rst b/docs/control-structures.rst
index 46e076e5..40070a20 100644
--- a/docs/control-structures.rst
+++ b/docs/control-structures.rst
@@ -284,10 +284,12 @@ Solidity internally allows tuple types, i.e. a list of objects of potentially di
}
function g() public {
- // Declares and assigns the variables. Specifying the type explicitly is not possible.
- var (x, b, y) = f();
- // Assigns to a pre-existing variable.
- (x, y) = (2, 7);
+ // Variables declared with type
+ uint x;
+ bool b;
+ uint y;
+ // Tuple values can be assigned to these pre-existing variables
+ (x, b, y) = f();
// Common trick to swap values -- does not work for non-value storage types.
(x, y) = (y, x);
// Components can be left out (also for variable declarations).
diff --git a/docs/introduction-to-smart-contracts.rst b/docs/introduction-to-smart-contracts.rst
index 56f0fe3e..84b1fff8 100644
--- a/docs/introduction-to-smart-contracts.rst
+++ b/docs/introduction-to-smart-contracts.rst
@@ -326,7 +326,13 @@ EVM bytecode and executed. The output of this execution is
permanently stored as the code of the contract.
This means that in order to create a contract, you do not
send the actual code of the contract, but in fact code that
-returns that code.
+returns that code when executed.
+
+.. note::
+ While a contract is being created, its code is still empty.
+ Because of that, you should not call back into the
+ contract under construction until its constructor has
+ finished executing.
.. index:: ! gas, ! gas price
diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst
index 01154854..20400aa2 100644
--- a/docs/miscellaneous.rst
+++ b/docs/miscellaneous.rst
@@ -64,12 +64,15 @@ The position of ``data[4][9].b`` is at ``keccak256(uint256(9) . keccak256(uint25
Layout in Memory
****************
-Solidity reserves three 256-bit slots:
+Solidity reserves four 32 byte slots:
-- 0 - 64: scratch space for hashing methods
-- 64 - 96: currently allocated memory size (aka. free memory pointer)
+- ``0x00`` - ``0x3f``: scratch space for hashing methods
+- ``0x40`` - ``0x5f``: currently allocated memory size (aka. free memory pointer)
+- ``0x60`` - ``0x7f``: zero slot
-Scratch space can be used between statements (ie. within inline assembly).
+Scratch space can be used between statements (ie. within inline assembly). The zero slot
+is used as initial value for dynamic memory arrays and should never be written to
+(the free memory pointer points to ``0x80`` initially).
Solidity always places new objects at the free memory pointer and memory is never freed (this might change in the future).
diff --git a/docs/solidity-by-example.rst b/docs/solidity-by-example.rst
index 27fefd49..3636a332 100644
--- a/docs/solidity-by-example.rst
+++ b/docs/solidity-by-example.rst
@@ -89,11 +89,10 @@ of votes.
function giveRightToVote(address voter) public {
// If the argument of `require` evaluates to `false`,
// it terminates and reverts all changes to
- // the state and to Ether balances. It is often
- // a good idea to use this if functions are
- // called incorrectly. But watch out, this
- // will currently also consume all provided gas
- // (this is planned to change in the future).
+ // the state and to Ether balances.
+ // This consumes all gas in old EVM versions, but not anymore.
+ // It is often a good idea to use this if functions are
+ // called incorrectly.
require(
(msg.sender == chairperson) &&
!voters[voter].voted &&
diff --git a/docs/units-and-global-variables.rst b/docs/units-and-global-variables.rst
index 2571f20a..e7f41ed1 100644
--- a/docs/units-and-global-variables.rst
+++ b/docs/units-and-global-variables.rst
@@ -169,6 +169,13 @@ For more information, see the section on :ref:`address`.
Use a pattern where the recipient withdraws the money.
.. note::
+ If storage variables are accessed via a low-level delegatecall, the storage layout of the two contracts
+ must align in order for the called contract to correctly access the storage variables of the calling contract by name.
+ This is of course not the case if storage pointers are passed as function arguments as in the case for
+ the high-level libraries.
+
+
+.. note::
The use of ``callcode`` is discouraged and will be removed in the future.
.. index:: this, selfdestruct
diff --git a/libdevcore/Algorithms.h b/libdevcore/Algorithms.h
new file mode 100644
index 00000000..b2540668
--- /dev/null
+++ b/libdevcore/Algorithms.h
@@ -0,0 +1,76 @@
+/*
+ This file is part of solidity.
+
+ solidity is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ solidity is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with solidity. If not, see <http://www.gnu.org/licenses/>.
+*/
+#pragma once
+
+
+#include <functional>
+#include <set>
+
+namespace dev
+{
+
+/**
+ * Detector for cycles in directed graphs. It returns the first
+ * vertex on the path towards a cycle or a nullptr if there is
+ * no reachable cycle starting from a given vertex.
+ */
+template <typename V>
+class CycleDetector
+{
+public:
+ /// Initializes the cycle detector
+ /// @param _visit function that is given the current vertex
+ /// and is supposed to call @a run on all
+ /// adjacent vertices.
+ explicit CycleDetector(std::function<void(V const&, CycleDetector&)> _visit):
+ m_visit(std::move(_visit))
+ { }
+
+ /// Recursively perform cycle detection starting
+ /// (or continuing) with @param _vertex
+ /// @returns the first vertex on the path towards a cycle from @a _vertex
+ /// or nullptr if no cycle is reachable from @a _vertex.
+ V const* run(V const& _vertex)
+ {
+ if (m_firstCycleVertex)
+ return m_firstCycleVertex;
+ if (m_processed.count(&_vertex))
+ return nullptr;
+ else if (m_processing.count(&_vertex))
+ return m_firstCycleVertex = &_vertex;
+ m_processing.insert(&_vertex);
+
+ m_depth++;
+ m_visit(_vertex, *this);
+ m_depth--;
+ if (m_firstCycleVertex && m_depth == 1)
+ m_firstCycleVertex = &_vertex;
+
+ m_processing.erase(&_vertex);
+ m_processed.insert(&_vertex);
+ return m_firstCycleVertex;
+ }
+
+private:
+ std::function<void(V const&, CycleDetector&)> m_visit;
+ std::set<V const*> m_processing;
+ std::set<V const*> m_processed;
+ size_t m_depth = 0;
+ V const* m_firstCycleVertex = nullptr;
+};
+
+}
diff --git a/libdevcore/CommonIO.cpp b/libdevcore/CommonIO.cpp
index 6526baf9..0063a8d4 100644
--- a/libdevcore/CommonIO.cpp
+++ b/libdevcore/CommonIO.cpp
@@ -167,3 +167,23 @@ int dev::readStandardInputChar()
DisableConsoleBuffering disableConsoleBuffering;
return cin.get();
}
+
+boost::filesystem::path dev::weaklyCanonicalFilesystemPath(boost::filesystem::path const &_path)
+{
+ if (boost::filesystem::exists(_path))
+ return boost::filesystem::canonical(_path);
+ else
+ {
+ boost::filesystem::path head(_path);
+ boost::filesystem::path tail;
+ for (auto it = --_path.end(); !head.empty(); --it)
+ {
+ if (boost::filesystem::exists(head))
+ break;
+ tail = (*it) / tail;
+ head.remove_filename();
+ }
+ head = boost::filesystem::canonical(head);
+ return head / tail;
+ }
+}
diff --git a/libdevcore/CommonIO.h b/libdevcore/CommonIO.h
index 3ecdb4c3..9ba68e74 100644
--- a/libdevcore/CommonIO.h
+++ b/libdevcore/CommonIO.h
@@ -25,6 +25,7 @@
#include <sstream>
#include <string>
+#include <boost/filesystem.hpp>
#include "Common.h"
namespace dev
@@ -57,4 +58,8 @@ std::string toString(_T const& _t)
return o.str();
}
+/// Partial implementation of boost::filesystem::weakly_canonical (available in boost>=1.60).
+/// Should be replaced by the boost implementation as soon as support for boost<1.60 can be dropped.
+boost::filesystem::path weaklyCanonicalFilesystemPath(boost::filesystem::path const &_path);
+
}
diff --git a/libevmasm/PeepholeOptimiser.cpp b/libevmasm/PeepholeOptimiser.cpp
index 168d1109..8a39de24 100644
--- a/libevmasm/PeepholeOptimiser.cpp
+++ b/libevmasm/PeepholeOptimiser.cpp
@@ -154,6 +154,51 @@ struct DoublePush: SimplePeepholeOptimizerMethod<DoublePush, 2>
}
};
+struct CommutativeSwap: SimplePeepholeOptimizerMethod<CommutativeSwap, 2>
+{
+ static bool applySimple(AssemblyItem const& _swap, AssemblyItem const& _op, std::back_insert_iterator<AssemblyItems> _out)
+ {
+ // Remove SWAP1 if following instruction is commutative
+ if (
+ _swap.type() == Operation &&
+ _swap.instruction() == Instruction::SWAP1 &&
+ SemanticInformation::isCommutativeOperation(_op)
+ )
+ {
+ *_out = _op;
+ return true;
+ }
+ else
+ return false;
+ }
+};
+
+struct SwapComparison: SimplePeepholeOptimizerMethod<SwapComparison, 2>
+{
+ static bool applySimple(AssemblyItem const& _swap, AssemblyItem const& _op, std::back_insert_iterator<AssemblyItems> _out)
+ {
+ map<Instruction, Instruction> swappableOps{
+ { Instruction::LT, Instruction::GT },
+ { Instruction::GT, Instruction::LT },
+ { Instruction::SLT, Instruction::SGT },
+ { Instruction::SGT, Instruction::SLT }
+ };
+
+ if (
+ _swap.type() == Operation &&
+ _swap.instruction() == Instruction::SWAP1 &&
+ _op.type() == Operation &&
+ swappableOps.count(_op.instruction())
+ )
+ {
+ *_out = swappableOps.at(_op.instruction());
+ return true;
+ }
+ else
+ return false;
+ }
+};
+
struct JumpToNext: SimplePeepholeOptimizerMethod<JumpToNext, 3>
{
static size_t applySimple(
@@ -260,7 +305,7 @@ bool PeepholeOptimiser::optimise()
{
OptimiserState state {m_items, 0, std::back_inserter(m_optimisedItems)};
while (state.i < m_items.size())
- applyMethods(state, PushPop(), OpPop(), DoublePush(), DoubleSwap(), JumpToNext(), UnreachableCode(), TagConjunctions(), Identity());
+ applyMethods(state, PushPop(), OpPop(), DoublePush(), DoubleSwap(), CommutativeSwap(), SwapComparison(), JumpToNext(), UnreachableCode(), TagConjunctions(), Identity());
if (m_optimisedItems.size() < m_items.size() || (
m_optimisedItems.size() == m_items.size() && (
eth::bytesRequired(m_optimisedItems, 3) < eth::bytesRequired(m_items, 3) ||
diff --git a/libevmasm/RuleList.h b/libevmasm/RuleList.h
index da522cec..abcf170c 100644
--- a/libevmasm/RuleList.h
+++ b/libevmasm/RuleList.h
@@ -89,6 +89,16 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleList(
u256 mask = (u256(1) << testBit) - 1;
return u256(boost::multiprecision::bit_test(B.d(), testBit) ? B.d() | ~mask : B.d() & mask);
}, false},
+ {{Instruction::SHL, {A, B}}, [=]{
+ if (A.d() > 255)
+ return u256(0);
+ return u256(bigint(B.d()) << unsigned(A.d()));
+ }, false},
+ {{Instruction::SHR, {A, B}}, [=]{
+ if (A.d() > 255)
+ return u256(0);
+ return B.d() >> unsigned(A.d());
+ }, false},
// invariants involving known constants
{{Instruction::ADD, {X, 0}}, [=]{ return X; }, false},
diff --git a/libjulia/optimiser/CommonSubexpressionEliminator.cpp b/libjulia/optimiser/CommonSubexpressionEliminator.cpp
new file mode 100644
index 00000000..229bd35e
--- /dev/null
+++ b/libjulia/optimiser/CommonSubexpressionEliminator.cpp
@@ -0,0 +1,48 @@
+/*(
+ This file is part of solidity.
+
+ solidity is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ solidity is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with solidity. If not, see <http://www.gnu.org/licenses/>.
+*/
+/**
+ * Optimisation stage that replaces expressions known to be the current value of a variable
+ * in scope by a reference to that variable.
+ */
+
+#include <libjulia/optimiser/CommonSubexpressionEliminator.h>
+
+#include <libjulia/optimiser/Metrics.h>
+#include <libjulia/optimiser/SyntacticalEquality.h>
+
+#include <libsolidity/inlineasm/AsmData.h>
+
+using namespace std;
+using namespace dev;
+using namespace dev::julia;
+
+void CommonSubexpressionEliminator::visit(Expression& _e)
+{
+ // Single exception for substitution: We do not substitute one variable for another.
+ if (_e.type() != typeid(Identifier))
+ // TODO this search rather inefficient.
+ for (auto const& var: m_value)
+ {
+ solAssert(var.second, "");
+ if (SyntacticalEqualityChecker::equal(_e, *var.second))
+ {
+ _e = Identifier{locationOf(_e), var.first};
+ break;
+ }
+ }
+ DataFlowAnalyzer::visit(_e);
+}
diff --git a/libjulia/optimiser/CommonSubexpressionEliminator.h b/libjulia/optimiser/CommonSubexpressionEliminator.h
new file mode 100644
index 00000000..a8ca3abb
--- /dev/null
+++ b/libjulia/optimiser/CommonSubexpressionEliminator.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of solidity.
+
+ solidity is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ solidity is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with solidity. If not, see <http://www.gnu.org/licenses/>.
+*/
+/**
+ * Optimisation stage that replaces expressions known to be the current value of a variable
+ * in scope by a reference to that variable.
+ */
+
+#pragma once
+
+#include <libjulia/optimiser/DataFlowAnalyzer.h>
+
+namespace dev
+{
+namespace julia
+{
+
+/**
+ * Optimisation stage that replaces expressions known to be the current value of a variable
+ * in scope by a reference to that variable.
+ *
+ * Prerequisite: Disambiguator
+ */
+class CommonSubexpressionEliminator: public DataFlowAnalyzer
+{
+protected:
+ using ASTModifier::visit;
+ virtual void visit(Expression& _e) override;
+};
+
+}
+}
diff --git a/libsolidity/analysis/ConstantEvaluator.cpp b/libsolidity/analysis/ConstantEvaluator.cpp
index 83f37f47..8659bbfd 100644
--- a/libsolidity/analysis/ConstantEvaluator.cpp
+++ b/libsolidity/analysis/ConstantEvaluator.cpp
@@ -87,6 +87,12 @@ void ConstantEvaluator::endVisit(Identifier const& _identifier)
setType(_identifier, type(*value));
}
+void ConstantEvaluator::endVisit(TupleExpression const& _tuple)
+{
+ if (!_tuple.isInlineArray() && _tuple.components().size() == 1)
+ setType(_tuple, type(*_tuple.components().front()));
+}
+
void ConstantEvaluator::setType(ASTNode const& _node, TypePointer const& _type)
{
if (_type && _type->category() == Type::Category::RationalNumber)
diff --git a/libsolidity/analysis/ConstantEvaluator.h b/libsolidity/analysis/ConstantEvaluator.h
index 77a357b6..ac3a24a1 100644
--- a/libsolidity/analysis/ConstantEvaluator.h
+++ b/libsolidity/analysis/ConstantEvaluator.h
@@ -56,6 +56,7 @@ private:
virtual void endVisit(UnaryOperation const& _operation);
virtual void endVisit(Literal const& _literal);
virtual void endVisit(Identifier const& _identifier);
+ virtual void endVisit(TupleExpression const& _tuple);
void setType(ASTNode const& _node, TypePointer const& _type);
TypePointer type(ASTNode const& _node);
diff --git a/libsolidity/analysis/PostTypeChecker.cpp b/libsolidity/analysis/PostTypeChecker.cpp
index fbc72e52..19d0b708 100644
--- a/libsolidity/analysis/PostTypeChecker.cpp
+++ b/libsolidity/analysis/PostTypeChecker.cpp
@@ -21,6 +21,8 @@
#include <libsolidity/interface/ErrorReporter.h>
#include <libsolidity/interface/Version.h>
+#include <libdevcore/Algorithms.h>
+
#include <boost/range/adaptor/map.hpp>
#include <memory>
@@ -47,7 +49,7 @@ void PostTypeChecker::endVisit(ContractDefinition const&)
{
solAssert(!m_currentConstVariable, "");
for (auto declaration: m_constVariables)
- if (auto identifier = findCycle(declaration))
+ if (auto identifier = findCycle(*declaration))
m_errorReporter.typeError(
declaration->location(),
"The value of the constant " + declaration->name() +
@@ -87,20 +89,24 @@ bool PostTypeChecker::visit(Identifier const& _identifier)
return true;
}
-VariableDeclaration const* PostTypeChecker::findCycle(
- VariableDeclaration const* _startingFrom,
- set<VariableDeclaration const*> const& _seen
-)
+VariableDeclaration const* PostTypeChecker::findCycle(VariableDeclaration const& _startingFrom)
{
- if (_seen.count(_startingFrom))
- return _startingFrom;
- else if (m_constVariableDependencies.count(_startingFrom))
+ auto visitor = [&](VariableDeclaration const& _variable, CycleDetector<VariableDeclaration>& _cycleDetector)
{
- set<VariableDeclaration const*> seen(_seen);
- seen.insert(_startingFrom);
- for (auto v: m_constVariableDependencies[_startingFrom])
- if (findCycle(v, seen))
- return v;
- }
- return nullptr;
+ // Iterating through the dependencies needs to be deterministic and thus cannot
+ // depend on the memory layout.
+ // Because of that, we sort by AST node id.
+ vector<VariableDeclaration const*> dependencies(
+ m_constVariableDependencies[&_variable].begin(),
+ m_constVariableDependencies[&_variable].end()
+ );
+ sort(dependencies.begin(), dependencies.end(), [](VariableDeclaration const* _a, VariableDeclaration const* _b) -> bool
+ {
+ return _a->id() < _b->id();
+ });
+ for (auto v: dependencies)
+ if (_cycleDetector.run(*v))
+ return;
+ };
+ return CycleDetector<VariableDeclaration>(visitor).run(_startingFrom);
}
diff --git a/libsolidity/analysis/PostTypeChecker.h b/libsolidity/analysis/PostTypeChecker.h
index bafc1ae6..4f9dac6e 100644
--- a/libsolidity/analysis/PostTypeChecker.h
+++ b/libsolidity/analysis/PostTypeChecker.h
@@ -55,10 +55,7 @@ private:
virtual bool visit(Identifier const& _identifier) override;
- VariableDeclaration const* findCycle(
- VariableDeclaration const* _startingFrom,
- std::set<VariableDeclaration const*> const& _seen = std::set<VariableDeclaration const*>{}
- );
+ VariableDeclaration const* findCycle(VariableDeclaration const& _startingFrom);
ErrorReporter& m_errorReporter;
diff --git a/libsolidity/analysis/StaticAnalyzer.cpp b/libsolidity/analysis/StaticAnalyzer.cpp
index d96f8748..33b0e296 100644
--- a/libsolidity/analysis/StaticAnalyzer.cpp
+++ b/libsolidity/analysis/StaticAnalyzer.cpp
@@ -78,13 +78,13 @@ void StaticAnalyzer::endVisit(FunctionDefinition const&)
for (auto const& var: m_localVarUseCount)
if (var.second == 0)
{
- if (var.first->isCallableParameter())
+ if (var.first.second->isCallableParameter())
m_errorReporter.warning(
- var.first->location(),
+ var.first.second->location(),
"Unused function parameter. Remove or comment out the variable name to silence this warning."
);
else
- m_errorReporter.warning(var.first->location(), "Unused local variable.");
+ m_errorReporter.warning(var.first.second->location(), "Unused local variable.");
}
m_localVarUseCount.clear();
@@ -97,7 +97,7 @@ bool StaticAnalyzer::visit(Identifier const& _identifier)
{
solAssert(!var->name().empty(), "");
if (var->isLocalVariable())
- m_localVarUseCount[var] += 1;
+ m_localVarUseCount[make_pair(var->id(), var)] += 1;
}
return true;
}
@@ -109,7 +109,7 @@ bool StaticAnalyzer::visit(VariableDeclaration const& _variable)
solAssert(_variable.isLocalVariable(), "");
if (_variable.name() != "")
// This is not a no-op, the entry might pre-exist.
- m_localVarUseCount[&_variable] += 0;
+ m_localVarUseCount[make_pair(_variable.id(), &_variable)] += 0;
}
else if (_variable.isStateVariable())
{
@@ -132,7 +132,7 @@ bool StaticAnalyzer::visit(Return const& _return)
if (m_currentFunction && _return.expression())
for (auto const& var: m_currentFunction->returnParameters())
if (!var->name().empty())
- m_localVarUseCount[var.get()] += 1;
+ m_localVarUseCount[make_pair(var->id(), var.get())] += 1;
return true;
}
@@ -224,7 +224,7 @@ bool StaticAnalyzer::visit(InlineAssembly const& _inlineAssembly)
{
solAssert(!var->name().empty(), "");
if (var->isLocalVariable())
- m_localVarUseCount[var] += 1;
+ m_localVarUseCount[make_pair(var->id(), var)] += 1;
}
}
diff --git a/libsolidity/analysis/StaticAnalyzer.h b/libsolidity/analysis/StaticAnalyzer.h
index 124c4e7c..0a806bbd 100644
--- a/libsolidity/analysis/StaticAnalyzer.h
+++ b/libsolidity/analysis/StaticAnalyzer.h
@@ -77,7 +77,9 @@ private:
bool m_nonPayablePublic = false;
/// Number of uses of each (named) local variable in a function, counter is initialized with zero.
- std::map<VariableDeclaration const*, int> m_localVarUseCount;
+ /// Pairs of AST ids and pointers are used as keys to ensure a deterministic order
+ /// when traversing.
+ std::map<std::pair<size_t, VariableDeclaration const*>, int> m_localVarUseCount;
FunctionDefinition const* m_currentFunction = nullptr;
diff --git a/libsolidity/analysis/SyntaxChecker.cpp b/libsolidity/analysis/SyntaxChecker.cpp
index b595c4d1..f648e5b4 100644
--- a/libsolidity/analysis/SyntaxChecker.cpp
+++ b/libsolidity/analysis/SyntaxChecker.cpp
@@ -216,7 +216,29 @@ bool SyntaxChecker::visit(FunctionDefinition const& _function)
if (v050 && _function.noVisibilitySpecified())
m_errorReporter.syntaxError(_function.location(), "No visibility specified.");
-
+
+ if (_function.isOldStyleConstructor())
+ {
+ if (v050)
+ m_errorReporter.syntaxError(
+ _function.location(),
+ "Functions are not allowed to have the same name as the contract. "
+ "If you intend this to be a constructor, use \"constructor(...) { ... }\" to define it."
+ );
+ else
+ m_errorReporter.warning(
+ _function.location(),
+ "Defining constructors as functions with the same name as the contract is deprecated. "
+ "Use \"constructor(...) { ... }\" instead."
+ );
+ }
+ if (!_function.isImplemented() && !_function.modifiers().empty())
+ {
+ if (v050)
+ m_errorReporter.syntaxError(_function.location(), "Functions without implementation cannot have modifiers.");
+ else
+ m_errorReporter.warning( _function.location(), "Modifiers of functions without implementation are ignored." );
+ }
return true;
}
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 620dfca4..8b57fc15 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -60,17 +60,7 @@ bool typeSupportedByOldABIEncoder(Type const& _type)
bool TypeChecker::checkTypeRequirements(ASTNode const& _contract)
{
- try
- {
- _contract.accept(*this);
- }
- catch (FatalError const&)
- {
- // We got a fatal error which required to stop further type checking, but we can
- // continue normally from here.
- if (m_errorReporter.errors().empty())
- throw; // Something is weird here, rather throw again.
- }
+ _contract.accept(*this);
return Error::containsOnlyWarnings(m_errorReporter.errors());
}
@@ -101,7 +91,7 @@ bool TypeChecker::visit(ContractDefinition const& _contract)
checkContractDuplicateEvents(_contract);
checkContractIllegalOverrides(_contract);
checkContractAbstractFunctions(_contract);
- checkContractAbstractConstructors(_contract);
+ checkContractBaseConstructorArguments(_contract);
FunctionDefinition const* function = _contract.constructor();
if (function)
@@ -291,42 +281,108 @@ void TypeChecker::checkContractAbstractFunctions(ContractDefinition const& _cont
}
}
-void TypeChecker::checkContractAbstractConstructors(ContractDefinition const& _contract)
+void TypeChecker::checkContractBaseConstructorArguments(ContractDefinition const& _contract)
{
- set<ContractDefinition const*> argumentsNeeded;
- // check that we get arguments for all base constructors that need it.
- // If not mark the contract as abstract (not fully implemented)
+ bool const v050 = _contract.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050);
vector<ContractDefinition const*> const& bases = _contract.annotation().linearizedBaseContracts;
- for (ContractDefinition const* contract: bases)
- if (FunctionDefinition const* constructor = contract->constructor())
- if (contract != &_contract && !constructor->parameters().empty())
- argumentsNeeded.insert(contract);
+ // Determine the arguments that are used for the base constructors.
for (ContractDefinition const* contract: bases)
{
if (FunctionDefinition const* constructor = contract->constructor())
for (auto const& modifier: constructor->modifiers())
{
- auto baseContract = dynamic_cast<ContractDefinition const*>(
- &dereference(*modifier->name())
- );
- if (baseContract)
- argumentsNeeded.erase(baseContract);
+ auto baseContract = dynamic_cast<ContractDefinition const*>(&dereference(*modifier->name()));
+ if (modifier->arguments())
+ {
+ if (baseContract && baseContract->constructor())
+ annotateBaseConstructorArguments(_contract, baseContract->constructor(), modifier.get());
+ }
+ else
+ {
+ if (v050)
+ m_errorReporter.declarationError(
+ modifier->location(),
+ "Modifier-style base constructor call without arguments."
+ );
+ else
+ m_errorReporter.warning(
+ modifier->location(),
+ "Modifier-style base constructor call without arguments."
+ );
+ }
}
-
for (ASTPointer<InheritanceSpecifier> const& base: contract->baseContracts())
{
auto baseContract = dynamic_cast<ContractDefinition const*>(&dereference(base->name()));
solAssert(baseContract, "");
- if (!base->arguments().empty())
- argumentsNeeded.erase(baseContract);
+
+ if (baseContract->constructor() && base->arguments() && !base->arguments()->empty())
+ annotateBaseConstructorArguments(_contract, baseContract->constructor(), base.get());
+ }
+ }
+
+ // check that we get arguments for all base constructors that need it.
+ // If not mark the contract as abstract (not fully implemented)
+ for (ContractDefinition const* contract: bases)
+ if (FunctionDefinition const* constructor = contract->constructor())
+ if (contract != &_contract && !constructor->parameters().empty())
+ if (!_contract.annotation().baseConstructorArguments.count(constructor))
+ _contract.annotation().unimplementedFunctions.push_back(constructor);
+}
+
+void TypeChecker::annotateBaseConstructorArguments(
+ ContractDefinition const& _currentContract,
+ FunctionDefinition const* _baseConstructor,
+ ASTNode const* _argumentNode
+)
+{
+ bool const v050 = _currentContract.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050);
+
+ solAssert(_baseConstructor, "");
+ solAssert(_argumentNode, "");
+
+ auto insertionResult = _currentContract.annotation().baseConstructorArguments.insert(
+ std::make_pair(_baseConstructor, _argumentNode)
+ );
+ if (!insertionResult.second)
+ {
+ ASTNode const* previousNode = insertionResult.first->second;
+
+ SourceLocation const* mainLocation = nullptr;
+ SecondarySourceLocation ssl;
+
+ if (
+ _currentContract.location().contains(previousNode->location()) ||
+ _currentContract.location().contains(_argumentNode->location())
+ )
+ {
+ mainLocation = &previousNode->location();
+ ssl.append("Second constructor call is here:", _argumentNode->location());
+ }
+ else
+ {
+ mainLocation = &_currentContract.location();
+ ssl.append("First constructor call is here: ", _argumentNode->location());
+ ssl.append("Second constructor call is here: ", previousNode->location());
}
+
+ if (v050)
+ m_errorReporter.declarationError(
+ *mainLocation,
+ ssl,
+ "Base constructor arguments given twice."
+ );
+ else
+ m_errorReporter.warning(
+ *mainLocation,
+ "Base constructor arguments given twice.",
+ ssl
+ );
}
- if (!argumentsNeeded.empty())
- for (ContractDefinition const* contract: argumentsNeeded)
- _contract.annotation().unimplementedFunctions.push_back(contract->constructor());
+
}
void TypeChecker::checkContractIllegalOverrides(ContractDefinition const& _contract)
@@ -506,30 +562,46 @@ void TypeChecker::endVisit(InheritanceSpecifier const& _inheritance)
// Interfaces do not have constructors, so there are zero parameters.
parameterTypes = ContractType(*base).newExpressionType()->parameterTypes();
- if (!arguments.empty() && parameterTypes.size() != arguments.size())
+ if (arguments)
{
- m_errorReporter.typeError(
- _inheritance.location(),
- "Wrong argument count for constructor call: " +
- toString(arguments.size()) +
- " arguments given but expected " +
- toString(parameterTypes.size()) +
- "."
- );
- return;
- }
+ bool v050 = m_scope->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050);
- for (size_t i = 0; i < arguments.size(); ++i)
- if (!type(*arguments[i])->isImplicitlyConvertibleTo(*parameterTypes[i]))
- m_errorReporter.typeError(
- arguments[i]->location(),
- "Invalid type for argument in constructor call. "
- "Invalid implicit conversion from " +
- type(*arguments[i])->toString() +
- " to " +
- parameterTypes[i]->toString() +
- " requested."
- );
+ if (parameterTypes.size() != arguments->size())
+ {
+ if (arguments->size() == 0 && !v050)
+ m_errorReporter.warning(
+ _inheritance.location(),
+ "Wrong argument count for constructor call: " +
+ toString(arguments->size()) +
+ " arguments given but expected " +
+ toString(parameterTypes.size()) +
+ "."
+ );
+ else
+ {
+ m_errorReporter.typeError(
+ _inheritance.location(),
+ "Wrong argument count for constructor call: " +
+ toString(arguments->size()) +
+ " arguments given but expected " +
+ toString(parameterTypes.size()) +
+ "."
+ );
+ return;
+ }
+ }
+ for (size_t i = 0; i < arguments->size(); ++i)
+ if (!type(*(*arguments)[i])->isImplicitlyConvertibleTo(*parameterTypes[i]))
+ m_errorReporter.typeError(
+ (*arguments)[i]->location(),
+ "Invalid type for argument in constructor call. "
+ "Invalid implicit conversion from " +
+ type(*(*arguments)[i])->toString() +
+ " to " +
+ parameterTypes[i]->toString() +
+ " requested."
+ );
+ }
}
void TypeChecker::endVisit(UsingForDirective const& _usingFor)
@@ -740,7 +812,8 @@ void TypeChecker::visitManually(
vector<ContractDefinition const*> const& _bases
)
{
- std::vector<ASTPointer<Expression>> const& arguments = _modifier.arguments();
+ std::vector<ASTPointer<Expression>> const& arguments =
+ _modifier.arguments() ? *_modifier.arguments() : std::vector<ASTPointer<Expression>>();
for (ASTPointer<Expression> const& argument: arguments)
argument->accept(*this);
_modifier.name()->accept(*this);
@@ -778,7 +851,7 @@ void TypeChecker::visitManually(
);
return;
}
- for (size_t i = 0; i < _modifier.arguments().size(); ++i)
+ for (size_t i = 0; i < arguments.size(); ++i)
if (!type(*arguments[i])->isImplicitlyConvertibleTo(*type(*(*parameters)[i])))
m_errorReporter.typeError(
arguments[i]->location(),
diff --git a/libsolidity/analysis/TypeChecker.h b/libsolidity/analysis/TypeChecker.h
index 2ba31232..2245abd6 100644
--- a/libsolidity/analysis/TypeChecker.h
+++ b/libsolidity/analysis/TypeChecker.h
@@ -73,7 +73,12 @@ private:
void checkFunctionOverride(FunctionDefinition const& function, FunctionDefinition const& super);
void overrideError(FunctionDefinition const& function, FunctionDefinition const& super, std::string message);
void checkContractAbstractFunctions(ContractDefinition const& _contract);
- void checkContractAbstractConstructors(ContractDefinition const& _contract);
+ void checkContractBaseConstructorArguments(ContractDefinition const& _contract);
+ void annotateBaseConstructorArguments(
+ ContractDefinition const& _currentContract,
+ FunctionDefinition const* _baseConstructor,
+ ASTNode const* _argumentNode
+ );
/// Checks that different functions with external visibility end up having different
/// external argument types (i.e. different signature).
void checkContractExternalTypeClashes(ContractDefinition const& _contract);
diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h
index 9c67d354..ae253f0c 100644
--- a/libsolidity/ast/AST.h
+++ b/libsolidity/ast/AST.h
@@ -425,19 +425,22 @@ public:
InheritanceSpecifier(
SourceLocation const& _location,
ASTPointer<UserDefinedTypeName> const& _baseName,
- std::vector<ASTPointer<Expression>> _arguments
+ std::unique_ptr<std::vector<ASTPointer<Expression>>> _arguments
):
- ASTNode(_location), m_baseName(_baseName), m_arguments(_arguments) {}
+ ASTNode(_location), m_baseName(_baseName), m_arguments(std::move(_arguments)) {}
virtual void accept(ASTVisitor& _visitor) override;
virtual void accept(ASTConstVisitor& _visitor) const override;
UserDefinedTypeName const& name() const { return *m_baseName; }
- std::vector<ASTPointer<Expression>> const& arguments() const { return m_arguments; }
+ // Returns nullptr if no argument list was given (``C``).
+ // If an argument list is given (``C(...)``), the arguments are returned
+ // as a vector of expressions. Note that this vector can be empty (``C()``).
+ std::vector<ASTPointer<Expression>> const* arguments() const { return m_arguments.get(); }
private:
ASTPointer<UserDefinedTypeName> m_baseName;
- std::vector<ASTPointer<Expression>> m_arguments;
+ std::unique_ptr<std::vector<ASTPointer<Expression>>> m_arguments;
};
/**
@@ -607,7 +610,8 @@ public:
StateMutability stateMutability() const { return m_stateMutability; }
bool isConstructor() const { return m_isConstructor; }
- bool isFallback() const { return name().empty(); }
+ bool isOldStyleConstructor() const { return m_isConstructor && !name().empty(); }
+ bool isFallback() const { return !m_isConstructor && name().empty(); }
bool isPayable() const { return m_stateMutability == StateMutability::Payable; }
std::vector<ASTPointer<ModifierInvocation>> const& modifiers() const { return m_functionModifiers; }
std::vector<ASTPointer<VariableDeclaration>> const& returnParameters() const { return m_returnParameters->parameters(); }
@@ -758,19 +762,22 @@ public:
ModifierInvocation(
SourceLocation const& _location,
ASTPointer<Identifier> const& _name,
- std::vector<ASTPointer<Expression>> _arguments
+ std::unique_ptr<std::vector<ASTPointer<Expression>>> _arguments
):
- ASTNode(_location), m_modifierName(_name), m_arguments(_arguments) {}
+ ASTNode(_location), m_modifierName(_name), m_arguments(std::move(_arguments)) {}
virtual void accept(ASTVisitor& _visitor) override;
virtual void accept(ASTConstVisitor& _visitor) const override;
ASTPointer<Identifier> const& name() const { return m_modifierName; }
- std::vector<ASTPointer<Expression>> const& arguments() const { return m_arguments; }
+ // Returns nullptr if no argument list was given (``mod``).
+ // If an argument list is given (``mod(...)``), the arguments are returned
+ // as a vector of expressions. Note that this vector can be empty (``mod()``).
+ std::vector<ASTPointer<Expression>> const* arguments() const { return m_arguments.get(); }
private:
ASTPointer<Identifier> m_modifierName;
- std::vector<ASTPointer<Expression>> m_arguments;
+ std::unique_ptr<std::vector<ASTPointer<Expression>>> m_arguments;
};
/**
diff --git a/libsolidity/ast/ASTAnnotations.h b/libsolidity/ast/ASTAnnotations.h
index 3d4236cc..5cbe42bd 100644
--- a/libsolidity/ast/ASTAnnotations.h
+++ b/libsolidity/ast/ASTAnnotations.h
@@ -90,6 +90,9 @@ struct ContractDefinitionAnnotation: TypeDeclarationAnnotation, DocumentedAnnota
/// List of contracts this contract creates, i.e. which need to be compiled first.
/// Also includes all contracts from @a linearizedBaseContracts.
std::set<ContractDefinition const*> contractDependencies;
+ /// Mapping containing the nodes that define the arguments for base constructors.
+ /// These can either be inheritance specifiers or modifier invocations.
+ std::map<FunctionDefinition const*, ASTNode const*> baseConstructorArguments;
};
struct FunctionDefinitionAnnotation: ASTAnnotation, DocumentedAnnotation
diff --git a/libsolidity/ast/ASTJsonConverter.cpp b/libsolidity/ast/ASTJsonConverter.cpp
index 4fef67c3..95ba3089 100644
--- a/libsolidity/ast/ASTJsonConverter.cpp
+++ b/libsolidity/ast/ASTJsonConverter.cpp
@@ -268,7 +268,7 @@ bool ASTJsonConverter::visit(InheritanceSpecifier const& _node)
{
setJsonNode(_node, "InheritanceSpecifier", {
make_pair("baseName", toJson(_node.name())),
- make_pair("arguments", toJson(_node.arguments()))
+ make_pair("arguments", _node.arguments() ? toJson(*_node.arguments()) : Json::nullValue)
});
return false;
}
@@ -378,7 +378,7 @@ bool ASTJsonConverter::visit(ModifierInvocation const& _node)
{
setJsonNode(_node, "ModifierInvocation", {
make_pair("modifierName", toJson(*_node.name())),
- make_pair("arguments", toJson(_node.arguments()))
+ make_pair("arguments", _node.arguments() ? toJson(*_node.arguments()) : Json::nullValue)
});
return false;
}
diff --git a/libsolidity/ast/AST_accept.h b/libsolidity/ast/AST_accept.h
index 70ee997e..aeff6e4a 100644
--- a/libsolidity/ast/AST_accept.h
+++ b/libsolidity/ast/AST_accept.h
@@ -94,7 +94,8 @@ void InheritanceSpecifier::accept(ASTVisitor& _visitor)
if (_visitor.visit(*this))
{
m_baseName->accept(_visitor);
- listAccept(m_arguments, _visitor);
+ if (m_arguments)
+ listAccept(*m_arguments, _visitor);
}
_visitor.endVisit(*this);
}
@@ -104,7 +105,8 @@ void InheritanceSpecifier::accept(ASTConstVisitor& _visitor) const
if (_visitor.visit(*this))
{
m_baseName->accept(_visitor);
- listAccept(m_arguments, _visitor);
+ if (m_arguments)
+ listAccept(*m_arguments, _visitor);
}
_visitor.endVisit(*this);
}
@@ -262,7 +264,8 @@ void ModifierInvocation::accept(ASTVisitor& _visitor)
if (_visitor.visit(*this))
{
m_modifierName->accept(_visitor);
- listAccept(m_arguments, _visitor);
+ if (m_arguments)
+ listAccept(*m_arguments, _visitor);
}
_visitor.endVisit(*this);
}
@@ -272,7 +275,8 @@ void ModifierInvocation::accept(ASTConstVisitor& _visitor) const
if (_visitor.visit(*this))
{
m_modifierName->accept(_visitor);
- listAccept(m_arguments, _visitor);
+ if (m_arguments)
+ listAccept(*m_arguments, _visitor);
}
_visitor.endVisit(*this);
}
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index 42fd1c3d..21353080 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -28,6 +28,7 @@
#include <libdevcore/CommonData.h>
#include <libdevcore/SHA3.h>
#include <libdevcore/UTF8.h>
+#include <libdevcore/Algorithms.h>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
@@ -232,11 +233,22 @@ TypePointer Type::fromElementaryTypeName(ElementaryTypeNameToken const& _type)
TypePointer Type::fromElementaryTypeName(string const& _name)
{
+ string name = _name;
+ DataLocation location = DataLocation::Storage;
+ if (boost::algorithm::ends_with(name, " memory"))
+ {
+ name = name.substr(0, name.length() - 7);
+ location = DataLocation::Memory;
+ }
unsigned short firstNum;
unsigned short secondNum;
Token::Value token;
- tie(token, firstNum, secondNum) = Token::fromIdentifierOrKeyword(_name);
- return fromElementaryTypeName(ElementaryTypeNameToken(token, firstNum, secondNum));
+ tie(token, firstNum, secondNum) = Token::fromIdentifierOrKeyword(name);
+ auto t = fromElementaryTypeName(ElementaryTypeNameToken(token, firstNum, secondNum));
+ if (auto* ref = dynamic_cast<ReferenceType const*>(t.get()))
+ return ref->copyForLocation(location, true);
+ else
+ return t;
}
TypePointer Type::forLiteral(Literal const& _literal)
@@ -827,10 +839,10 @@ TypePointer RationalNumberType::binaryOperatorResult(Token::Value _operator, Typ
{
if (_other->category() == Category::Integer || _other->category() == Category::FixedPoint)
{
- auto mobile = mobileType();
- if (!mobile)
+ auto commonType = Type::commonType(shared_from_this(), _other);
+ if (!commonType)
return TypePointer();
- return mobile->binaryOperatorResult(_operator, _other);
+ return commonType->binaryOperatorResult(_operator, _other);
}
else if (_other->category() != category())
return TypePointer();
@@ -1971,25 +1983,19 @@ bool StructType::recursive() const
{
if (!m_recursive.is_initialized())
{
- set<StructDefinition const*> structsSeen;
- function<bool(StructType const*)> check = [&](StructType const* t) -> bool
+ auto visitor = [&](StructDefinition const& _struct, CycleDetector<StructDefinition>& _cycleDetector)
{
- StructDefinition const* str = &t->structDefinition();
- if (structsSeen.count(str))
- return true;
- structsSeen.insert(str);
- for (ASTPointer<VariableDeclaration> const& variable: str->members())
+ for (ASTPointer<VariableDeclaration> const& variable: _struct.members())
{
Type const* memberType = variable->annotation().type.get();
while (dynamic_cast<ArrayType const*>(memberType))
memberType = dynamic_cast<ArrayType const*>(memberType)->baseType().get();
if (StructType const* innerStruct = dynamic_cast<StructType const*>(memberType))
- if (check(innerStruct))
- return true;
+ if (_cycleDetector.run(innerStruct->structDefinition()))
+ return;
}
- return false;
};
- m_recursive = check(this);
+ m_recursive = (CycleDetector<StructDefinition>(visitor).run(structDefinition()) != nullptr);
}
return *m_recursive;
}
diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h
index 2c392705..05f506f1 100644
--- a/libsolidity/ast/Types.h
+++ b/libsolidity/ast/Types.h
@@ -150,6 +150,7 @@ public:
/// @name Factory functions
/// Factory functions that convert an AST @ref TypeName to a Type.
static TypePointer fromElementaryTypeName(ElementaryTypeNameToken const& _type);
+ /// Converts a given elementary type name with optional suffix " memory" to a type pointer.
static TypePointer fromElementaryTypeName(std::string const& _name);
/// @}
@@ -402,7 +403,7 @@ private:
};
/**
- * Integer and fixed point constants either literals or computed.
+ * Integer and fixed point constants either literals or computed.
* Example expressions: 2, 3.14, 2+10.2, ~10.
* There is one distinct type per value.
*/
@@ -414,7 +415,7 @@ public:
/// @returns true if the literal is a valid integer.
static std::tuple<bool, rational> isValidLiteral(Literal const& _literal);
-
+
explicit RationalNumberType(rational const& _value):
m_value(_value)
{}
@@ -435,7 +436,7 @@ public:
/// @returns the smallest integer type that can hold the value or an empty pointer if not possible.
std::shared_ptr<IntegerType const> integerType() const;
- /// @returns the smallest fixed type that can hold the value or incurs the least precision loss.
+ /// @returns the smallest fixed type that can hold the value or incurs the least precision loss.
/// If the integer part does not fit, returns an empty pointer.
std::shared_ptr<FixedPointType const> fixedPointType() const;
@@ -777,7 +778,7 @@ public:
virtual std::string canonicalName() const override;
virtual std::string signatureInExternalFunction(bool _structsByName) const override;
- /// @returns a function that peforms the type conversion between a list of struct members
+ /// @returns a function that performs the type conversion between a list of struct members
/// and a memory struct of this type.
FunctionTypePointer constructorType() const;
@@ -1038,7 +1039,7 @@ public:
return *m_declaration;
}
bool hasDeclaration() const { return !!m_declaration; }
- /// @returns true if the the result of this function only depends on its arguments
+ /// @returns true if the result of this function only depends on its arguments
/// and it does not modify the state.
/// Currently, this will only return true for internal functions like keccak and ecrecover.
bool isPure() const;
@@ -1055,7 +1056,7 @@ public:
bool bound() const { return m_bound; }
/// @returns a copy of this type, where gas or value are set manually. This will never set one
- /// of the parameters to fals.
+ /// of the parameters to false.
TypePointer copyAndSetGasOrValue(bool _setGas, bool _setValue) const;
/// @returns a copy of this function type where all return parameters of dynamic size are
diff --git a/libsolidity/codegen/ArrayUtils.cpp b/libsolidity/codegen/ArrayUtils.cpp
index 4703fc1f..0fe66d2d 100644
--- a/libsolidity/codegen/ArrayUtils.cpp
+++ b/libsolidity/codegen/ArrayUtils.cpp
@@ -774,6 +774,55 @@ void ArrayUtils::resizeDynamicArray(ArrayType const& _typeIn) const
);
}
+void ArrayUtils::incrementDynamicArraySize(ArrayType const& _type) const
+{
+ solAssert(_type.location() == DataLocation::Storage, "");
+ solAssert(_type.isDynamicallySized(), "");
+ if (!_type.isByteArray() && _type.baseType()->storageBytes() < 32)
+ solAssert(_type.baseType()->isValueType(), "Invalid storage size for non-value type.");
+
+ if (_type.isByteArray())
+ {
+ // We almost always just add 2 (length of byte arrays is shifted left by one)
+ // except for the case where we transition from a short byte array
+ // to a long byte array, there we have to copy.
+ // This happens if the length is exactly 31, which means that the
+ // lowest-order byte (we actually use a mask with fewer bits) must
+ // be (31*2+0) = 62
+
+ m_context.appendInlineAssembly(R"({
+ let data := sload(ref)
+ let shifted_length := and(data, 63)
+ // We have to copy if length is exactly 31, because that marks
+ // the transition between in-place and out-of-place storage.
+ switch shifted_length
+ case 62
+ {
+ mstore(0, ref)
+ let data_area := keccak256(0, 0x20)
+ sstore(data_area, and(data, not(0xff)))
+ // New length is 32, encoded as (32 * 2 + 1)
+ sstore(ref, 65)
+ // Replace ref variable by new length
+ ref := 32
+ }
+ default
+ {
+ sstore(ref, add(data, 2))
+ // Replace ref variable by new length
+ if iszero(and(data, 1)) { data := shifted_length }
+ ref := add(div(data, 2), 1)
+ }
+ })", {"ref"});
+ }
+ else
+ m_context.appendInlineAssembly(R"({
+ let new_length := add(sload(ref), 1)
+ sstore(ref, new_length)
+ ref := new_length
+ })", {"ref"});
+}
+
void ArrayUtils::clearStorageLoop(TypePointer const& _type) const
{
m_context.callLowLevelFunction(
diff --git a/libsolidity/codegen/ArrayUtils.h b/libsolidity/codegen/ArrayUtils.h
index f3ddc4ee..99786397 100644
--- a/libsolidity/codegen/ArrayUtils.h
+++ b/libsolidity/codegen/ArrayUtils.h
@@ -67,6 +67,12 @@ public:
/// Stack pre: reference (excludes byte offset) new_length
/// Stack post:
void resizeDynamicArray(ArrayType const& _type) const;
+ /// Increments the size of a dynamic array by one.
+ /// Does not touch the new data element. In case of a byte array, this might move the
+ /// data.
+ /// Stack pre: reference (excludes byte offset)
+ /// Stack post: new_length
+ void incrementDynamicArraySize(ArrayType const& _type) const;
/// Appends a loop that clears a sequence of storage slots of the given type (excluding end).
/// Stack pre: end_ref start_ref
/// Stack post: end_ref
diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp
index deaef017..79aef7b0 100644
--- a/libsolidity/codegen/CompilerUtils.cpp
+++ b/libsolidity/codegen/CompilerUtils.cpp
@@ -21,6 +21,7 @@
*/
#include <libsolidity/codegen/CompilerUtils.h>
+
#include <libsolidity/ast/AST.h>
#include <libsolidity/codegen/ArrayUtils.h>
#include <libsolidity/codegen/LValue.h>
@@ -39,11 +40,17 @@ namespace solidity
const unsigned CompilerUtils::dataStartOffset = 4;
const size_t CompilerUtils::freeMemoryPointer = 64;
+const size_t CompilerUtils::zeroPointer = CompilerUtils::freeMemoryPointer + 32;
+const size_t CompilerUtils::generalPurposeMemoryStart = CompilerUtils::zeroPointer + 32;
const unsigned CompilerUtils::identityContractAddress = 4;
+static_assert(CompilerUtils::freeMemoryPointer >= 64, "Free memory pointer must not overlap with scratch area.");
+static_assert(CompilerUtils::zeroPointer >= CompilerUtils::freeMemoryPointer + 32, "Zero pointer must not overlap with free memory pointer.");
+static_assert(CompilerUtils::generalPurposeMemoryStart >= CompilerUtils::zeroPointer + 32, "General purpose memory must not overlap with zero area.");
+
void CompilerUtils::initialiseFreeMemoryPointer()
{
- m_context << u256(freeMemoryPointer + 32);
+ m_context << u256(generalPurposeMemoryStart);
storeFreeMemoryPointer();
}
@@ -1051,6 +1058,13 @@ void CompilerUtils::pushZeroValue(Type const& _type)
return;
}
solAssert(referenceType->location() == DataLocation::Memory, "");
+ if (auto arrayType = dynamic_cast<ArrayType const*>(&_type))
+ if (arrayType->isDynamicallySized())
+ {
+ // Push a memory location that is (hopefully) always zero.
+ pushZeroPointer();
+ return;
+ }
TypePointer type = _type.shared_from_this();
m_context.callLowLevelFunction(
@@ -1071,13 +1085,8 @@ void CompilerUtils::pushZeroValue(Type const& _type)
}
else if (auto arrayType = dynamic_cast<ArrayType const*>(type.get()))
{
- if (arrayType->isDynamicallySized())
- {
- // zero length
- _context << u256(0);
- utils.storeInMemoryDynamic(IntegerType(256));
- }
- else if (arrayType->length() > 0)
+ solAssert(!arrayType->isDynamicallySized(), "");
+ if (arrayType->length() > 0)
{
_context << arrayType->length() << Instruction::SWAP1;
// stack: items_to_do memory_pos
@@ -1094,6 +1103,11 @@ void CompilerUtils::pushZeroValue(Type const& _type)
);
}
+void CompilerUtils::pushZeroPointer()
+{
+ m_context << u256(zeroPointer);
+}
+
void CompilerUtils::moveToStackVariable(VariableDeclaration const& _variable)
{
unsigned const stackPosition = m_context.baseToCurrentStackOffset(m_context.baseStackOffsetOfVariable(_variable));
diff --git a/libsolidity/codegen/CompilerUtils.h b/libsolidity/codegen/CompilerUtils.h
index 389673ef..a32c5c6e 100644
--- a/libsolidity/codegen/CompilerUtils.h
+++ b/libsolidity/codegen/CompilerUtils.h
@@ -210,6 +210,9 @@ public:
/// Creates a zero-value for the given type and puts it onto the stack. This might allocate
/// memory for memory references.
void pushZeroValue(Type const& _type);
+ /// Pushes a pointer to the stack that points to a (potentially shared) location in memory
+ /// that always contains a zero. It is not allowed to write there.
+ void pushZeroPointer();
/// Moves the value that is at the top of the stack to a stack variable.
void moveToStackVariable(VariableDeclaration const& _variable);
@@ -255,6 +258,10 @@ public:
/// Position of the free-memory-pointer in memory;
static const size_t freeMemoryPointer;
+ /// Position of the memory slot that is always zero.
+ static const size_t zeroPointer;
+ /// Starting offset for memory available to the user (aka the contract).
+ static const size_t generalPurposeMemoryStart;
private:
/// Address of the precompiled identity contract.
diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp
index ebd9139a..5cb37103 100644
--- a/libsolidity/codegen/ContractCompiler.cpp
+++ b/libsolidity/codegen/ContractCompiler.cpp
@@ -135,34 +135,13 @@ void ContractCompiler::appendInitAndConstructorCode(ContractDefinition const& _c
{
solAssert(!_contract.isLibrary(), "Tried to initialize library.");
CompilerContext::LocationSetter locationSetter(m_context, _contract);
- // Determine the arguments that are used for the base constructors.
- std::vector<ContractDefinition const*> const& bases = _contract.annotation().linearizedBaseContracts;
- for (ContractDefinition const* contract: bases)
- {
- if (FunctionDefinition const* constructor = contract->constructor())
- for (auto const& modifier: constructor->modifiers())
- {
- auto baseContract = dynamic_cast<ContractDefinition const*>(
- modifier->name()->annotation().referencedDeclaration
- );
- if (baseContract && !modifier->arguments().empty())
- if (m_baseArguments.count(baseContract->constructor()) == 0)
- m_baseArguments[baseContract->constructor()] = &modifier->arguments();
- }
- for (ASTPointer<InheritanceSpecifier> const& base: contract->baseContracts())
- {
- ContractDefinition const* baseContract = dynamic_cast<ContractDefinition const*>(
- base->name().annotation().referencedDeclaration
- );
- solAssert(baseContract, "");
+ m_baseArguments = &_contract.annotation().baseConstructorArguments;
- if (!m_baseArguments.count(baseContract->constructor()) && !base->arguments().empty())
- m_baseArguments[baseContract->constructor()] = &base->arguments();
- }
- }
// Initialization of state variables in base-to-derived order.
- for (ContractDefinition const* contract: boost::adaptors::reverse(bases))
+ for (ContractDefinition const* contract: boost::adaptors::reverse(
+ _contract.annotation().linearizedBaseContracts
+ ))
initializeStateVariables(*contract);
if (FunctionDefinition const* constructor = _contract.constructor())
@@ -236,8 +215,14 @@ void ContractCompiler::appendBaseConstructor(FunctionDefinition const& _construc
FunctionType constructorType(_constructor);
if (!constructorType.parameterTypes().empty())
{
- solAssert(m_baseArguments.count(&_constructor), "");
- std::vector<ASTPointer<Expression>> const* arguments = m_baseArguments[&_constructor];
+ solAssert(m_baseArguments, "");
+ solAssert(m_baseArguments->count(&_constructor), "");
+ std::vector<ASTPointer<Expression>> const* arguments = nullptr;
+ ASTNode const* baseArgumentNode = m_baseArguments->at(&_constructor);
+ if (auto inheritanceSpecifier = dynamic_cast<InheritanceSpecifier const*>(baseArgumentNode))
+ arguments = inheritanceSpecifier->arguments();
+ else if (auto modifierInvocation = dynamic_cast<ModifierInvocation const*>(baseArgumentNode))
+ arguments = modifierInvocation->arguments();
solAssert(arguments, "");
solAssert(arguments->size() == constructorType.parameterTypes().size(), "");
for (unsigned i = 0; i < arguments->size(); ++i)
@@ -912,13 +897,16 @@ void ContractCompiler::appendModifierOrFunctionCode()
);
ModifierDefinition const& modifier = m_context.resolveVirtualFunctionModifier(nonVirtualModifier);
CompilerContext::LocationSetter locationSetter(m_context, modifier);
- solAssert(modifier.parameters().size() == modifierInvocation->arguments().size(), "");
+ std::vector<ASTPointer<Expression>> const& modifierArguments =
+ modifierInvocation->arguments() ? *modifierInvocation->arguments() : std::vector<ASTPointer<Expression>>();
+
+ solAssert(modifier.parameters().size() == modifierArguments.size(), "");
for (unsigned i = 0; i < modifier.parameters().size(); ++i)
{
m_context.addVariable(*modifier.parameters()[i]);
addedVariables.push_back(modifier.parameters()[i].get());
compileExpression(
- *modifierInvocation->arguments()[i],
+ *modifierArguments[i],
modifier.parameters()[i]->annotation().type
);
}
diff --git a/libsolidity/codegen/ContractCompiler.h b/libsolidity/codegen/ContractCompiler.h
index e04a56fb..02a3452f 100644
--- a/libsolidity/codegen/ContractCompiler.h
+++ b/libsolidity/codegen/ContractCompiler.h
@@ -135,7 +135,7 @@ private:
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*, std::vector<ASTPointer<Expression>> const*> m_baseArguments;
+ std::map<FunctionDefinition const*, ASTNode const*> const* m_baseArguments;
};
}
diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp
index 76aa6843..57d49ac6 100644
--- a/libsolidity/codegen/ExpressionCompiler.cpp
+++ b/libsolidity/codegen/ExpressionCompiler.cpp
@@ -821,24 +821,27 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
function.kind() == FunctionType::Kind::ArrayPush ?
make_shared<ArrayType>(DataLocation::Storage, paramType) :
make_shared<ArrayType>(DataLocation::Storage);
- // get the current length
- ArrayUtils(m_context).retrieveLength(*arrayType);
- m_context << Instruction::DUP1;
- // stack: ArrayReference currentLength currentLength
- m_context << u256(1) << Instruction::ADD;
- // stack: ArrayReference currentLength newLength
- m_context << Instruction::DUP3 << Instruction::DUP2;
- ArrayUtils(m_context).resizeDynamicArray(*arrayType);
- m_context << Instruction::SWAP2 << Instruction::SWAP1;
- // stack: newLength ArrayReference oldLength
- ArrayUtils(m_context).accessIndex(*arrayType, false);
- // stack: newLength storageSlot slotOffset
+ // stack: ArrayReference
arguments[0]->accept(*this);
+ TypePointer const& argType = arguments[0]->annotation().type;
+ // stack: ArrayReference argValue
+ utils().moveToStackTop(argType->sizeOnStack(), 1);
+ // stack: argValue ArrayReference
+ m_context << Instruction::DUP1;
+ ArrayUtils(m_context).incrementDynamicArraySize(*arrayType);
+ // stack: argValue ArrayReference newLength
+ m_context << Instruction::SWAP1;
+ // stack: argValue newLength ArrayReference
+ m_context << u256(1) << Instruction::DUP3 << Instruction::SUB;
+ // stack: argValue newLength ArrayReference (newLength-1)
+ ArrayUtils(m_context).accessIndex(*arrayType, false);
+ // stack: argValue newLength storageSlot slotOffset
+ utils().moveToStackTop(3, argType->sizeOnStack());
// stack: newLength storageSlot slotOffset argValue
TypePointer type = arguments[0]->annotation().type->closestTemporaryType(arrayType->baseType());
solAssert(type, "");
- utils().convertType(*arguments[0]->annotation().type, *type);
+ utils().convertType(*argType, *type);
utils().moveToStackTop(1 + type->sizeOnStack());
utils().moveToStackTop(1 + type->sizeOnStack());
// stack: newLength argValue storageSlot slotOffset
diff --git a/libsolidity/formal/SymbolicBoolVariable.cpp b/libsolidity/formal/SymbolicBoolVariable.cpp
index e5c56e46..5cf22d7d 100644
--- a/libsolidity/formal/SymbolicBoolVariable.cpp
+++ b/libsolidity/formal/SymbolicBoolVariable.cpp
@@ -30,7 +30,11 @@ SymbolicBoolVariable::SymbolicBoolVariable(
SymbolicVariable(_decl, _interface)
{
solAssert(m_declaration.type()->category() == Type::Category::Bool, "");
- m_expression = make_shared<smt::Expression>(m_interface.newFunction(uniqueSymbol(), smt::Sort::Int, smt::Sort::Bool));
+}
+
+smt::Expression SymbolicBoolVariable::valueAtSequence(int _seq) const
+{
+ return m_interface.newBool(uniqueSymbol(_seq));
}
void SymbolicBoolVariable::setZeroValue(int _seq)
diff --git a/libsolidity/formal/SymbolicBoolVariable.h b/libsolidity/formal/SymbolicBoolVariable.h
index 3510b770..678f97d9 100644
--- a/libsolidity/formal/SymbolicBoolVariable.h
+++ b/libsolidity/formal/SymbolicBoolVariable.h
@@ -41,6 +41,9 @@ public:
void setZeroValue(int _seq);
/// Does nothing since the SMT solver already knows the valid values.
void setUnknownValue(int _seq);
+
+protected:
+ smt::Expression valueAtSequence(int _seq) const;
};
}
diff --git a/libsolidity/formal/SymbolicIntVariable.cpp b/libsolidity/formal/SymbolicIntVariable.cpp
index eb7b1c17..5e71fdcc 100644
--- a/libsolidity/formal/SymbolicIntVariable.cpp
+++ b/libsolidity/formal/SymbolicIntVariable.cpp
@@ -30,7 +30,11 @@ SymbolicIntVariable::SymbolicIntVariable(
SymbolicVariable(_decl, _interface)
{
solAssert(m_declaration.type()->category() == Type::Category::Integer, "");
- m_expression = make_shared<smt::Expression>(m_interface.newFunction(uniqueSymbol(), smt::Sort::Int, smt::Sort::Int));
+}
+
+smt::Expression SymbolicIntVariable::valueAtSequence(int _seq) const
+{
+ return m_interface.newInteger(uniqueSymbol(_seq));
}
void SymbolicIntVariable::setZeroValue(int _seq)
diff --git a/libsolidity/formal/SymbolicIntVariable.h b/libsolidity/formal/SymbolicIntVariable.h
index eb36b899..d591e8db 100644
--- a/libsolidity/formal/SymbolicIntVariable.h
+++ b/libsolidity/formal/SymbolicIntVariable.h
@@ -44,6 +44,9 @@ public:
static smt::Expression minValue(IntegerType const& _t);
static smt::Expression maxValue(IntegerType const& _t);
+
+protected:
+ smt::Expression valueAtSequence(int _seq) const;
};
}
diff --git a/libsolidity/formal/SymbolicVariable.cpp b/libsolidity/formal/SymbolicVariable.cpp
index d59b55b1..caefa3a3 100644
--- a/libsolidity/formal/SymbolicVariable.cpp
+++ b/libsolidity/formal/SymbolicVariable.cpp
@@ -32,9 +32,9 @@ SymbolicVariable::SymbolicVariable(
{
}
-string SymbolicVariable::uniqueSymbol() const
+string SymbolicVariable::uniqueSymbol(int _seq) const
{
- return m_declaration.name() + "_" + to_string(m_declaration.id());
+ return m_declaration.name() + "_" + to_string(m_declaration.id()) + "_" + to_string(_seq);
}
diff --git a/libsolidity/formal/SymbolicVariable.h b/libsolidity/formal/SymbolicVariable.h
index 75eb9fa5..e4e4ea8d 100644
--- a/libsolidity/formal/SymbolicVariable.h
+++ b/libsolidity/formal/SymbolicVariable.h
@@ -46,7 +46,7 @@ public:
return valueAtSequence(_seq);
}
- std::string uniqueSymbol() const;
+ std::string uniqueSymbol(int _seq) const;
/// Sets the var to the default value of its type.
virtual void setZeroValue(int _seq) = 0;
@@ -55,13 +55,9 @@ public:
virtual void setUnknownValue(int _seq) = 0;
protected:
- smt::Expression valueAtSequence(int _seq) const
- {
- return (*m_expression)(_seq);
- }
+ virtual smt::Expression valueAtSequence(int _seq) const = 0;
Declaration const& m_declaration;
- std::shared_ptr<smt::Expression> m_expression = nullptr;
smt::SolverInterface& m_interface;
};
diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp
index eacfca9c..4ff14aa2 100644
--- a/libsolidity/interface/CompilerStack.cpp
+++ b/libsolidity/interface/CompilerStack.cpp
@@ -164,85 +164,94 @@ bool CompilerStack::analyze()
resolveImports();
bool noErrors = true;
- SyntaxChecker syntaxChecker(m_errorReporter);
- for (Source const* source: m_sourceOrder)
- if (!syntaxChecker.checkSyntax(*source->ast))
- noErrors = false;
-
- DocStringAnalyser docStringAnalyser(m_errorReporter);
- for (Source const* source: m_sourceOrder)
- if (!docStringAnalyser.analyseDocStrings(*source->ast))
- noErrors = false;
- m_globalContext = make_shared<GlobalContext>();
- NameAndTypeResolver resolver(m_globalContext->declarations(), m_scopes, m_errorReporter);
- for (Source const* source: m_sourceOrder)
- if (!resolver.registerDeclarations(*source->ast))
- return false;
-
- map<string, SourceUnit const*> sourceUnitsByName;
- for (auto& source: m_sources)
- sourceUnitsByName[source.first] = source.second.ast.get();
- for (Source const* source: m_sourceOrder)
- if (!resolver.performImports(*source->ast, sourceUnitsByName))
- return false;
+ try {
+ SyntaxChecker syntaxChecker(m_errorReporter);
+ for (Source const* source: m_sourceOrder)
+ if (!syntaxChecker.checkSyntax(*source->ast))
+ noErrors = false;
- for (Source const* source: m_sourceOrder)
- for (ASTPointer<ASTNode> const& node: source->ast->nodes())
- if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
- {
- m_globalContext->setCurrentContract(*contract);
- if (!resolver.updateDeclaration(*m_globalContext->currentThis())) return false;
- if (!resolver.updateDeclaration(*m_globalContext->currentSuper())) return false;
- if (!resolver.resolveNamesAndTypes(*contract)) return false;
-
- // Note that we now reference contracts by their fully qualified names, and
- // thus contracts can only conflict if declared in the same source file. This
- // already causes a double-declaration error elsewhere, so we do not report
- // an error here and instead silently drop any additional contracts we find.
-
- if (m_contracts.find(contract->fullyQualifiedName()) == m_contracts.end())
- m_contracts[contract->fullyQualifiedName()].contract = contract;
- }
+ DocStringAnalyser docStringAnalyser(m_errorReporter);
+ for (Source const* source: m_sourceOrder)
+ if (!docStringAnalyser.analyseDocStrings(*source->ast))
+ noErrors = false;
- TypeChecker typeChecker(m_evmVersion, m_errorReporter);
- for (Source const* source: m_sourceOrder)
- for (ASTPointer<ASTNode> const& node: source->ast->nodes())
- if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
- if (!typeChecker.checkTypeRequirements(*contract))
- noErrors = false;
+ m_globalContext = make_shared<GlobalContext>();
+ NameAndTypeResolver resolver(m_globalContext->declarations(), m_scopes, m_errorReporter);
+ for (Source const* source: m_sourceOrder)
+ if (!resolver.registerDeclarations(*source->ast))
+ return false;
- if (noErrors)
- {
- PostTypeChecker postTypeChecker(m_errorReporter);
+ map<string, SourceUnit const*> sourceUnitsByName;
+ for (auto& source: m_sources)
+ sourceUnitsByName[source.first] = source.second.ast.get();
for (Source const* source: m_sourceOrder)
- if (!postTypeChecker.check(*source->ast))
- noErrors = false;
- }
+ if (!resolver.performImports(*source->ast, sourceUnitsByName))
+ return false;
- if (noErrors)
- {
- StaticAnalyzer staticAnalyzer(m_errorReporter);
for (Source const* source: m_sourceOrder)
- if (!staticAnalyzer.analyze(*source->ast))
- noErrors = false;
- }
+ for (ASTPointer<ASTNode> const& node: source->ast->nodes())
+ if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
+ {
+ m_globalContext->setCurrentContract(*contract);
+ if (!resolver.updateDeclaration(*m_globalContext->currentThis())) return false;
+ if (!resolver.updateDeclaration(*m_globalContext->currentSuper())) return false;
+ if (!resolver.resolveNamesAndTypes(*contract)) return false;
+
+ // Note that we now reference contracts by their fully qualified names, and
+ // thus contracts can only conflict if declared in the same source file. This
+ // already causes a double-declaration error elsewhere, so we do not report
+ // an error here and instead silently drop any additional contracts we find.
+
+ if (m_contracts.find(contract->fullyQualifiedName()) == m_contracts.end())
+ m_contracts[contract->fullyQualifiedName()].contract = contract;
+ }
- if (noErrors)
- {
- vector<ASTPointer<ASTNode>> ast;
+ TypeChecker typeChecker(m_evmVersion, m_errorReporter);
for (Source const* source: m_sourceOrder)
- ast.push_back(source->ast);
+ for (ASTPointer<ASTNode> const& node: source->ast->nodes())
+ if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
+ if (!typeChecker.checkTypeRequirements(*contract))
+ noErrors = false;
- if (!ViewPureChecker(ast, m_errorReporter).check())
- noErrors = false;
- }
+ if (noErrors)
+ {
+ PostTypeChecker postTypeChecker(m_errorReporter);
+ for (Source const* source: m_sourceOrder)
+ if (!postTypeChecker.check(*source->ast))
+ noErrors = false;
+ }
- if (noErrors)
+ if (noErrors)
+ {
+ StaticAnalyzer staticAnalyzer(m_errorReporter);
+ for (Source const* source: m_sourceOrder)
+ if (!staticAnalyzer.analyze(*source->ast))
+ noErrors = false;
+ }
+
+ if (noErrors)
+ {
+ vector<ASTPointer<ASTNode>> ast;
+ for (Source const* source: m_sourceOrder)
+ ast.push_back(source->ast);
+
+ if (!ViewPureChecker(ast, m_errorReporter).check())
+ noErrors = false;
+ }
+
+ if (noErrors)
+ {
+ SMTChecker smtChecker(m_errorReporter, m_smtQuery);
+ for (Source const* source: m_sourceOrder)
+ smtChecker.analyze(*source->ast);
+ }
+ }
+ catch(FatalError const&)
{
- SMTChecker smtChecker(m_errorReporter, m_smtQuery);
- for (Source const* source: m_sourceOrder)
- smtChecker.analyze(*source->ast);
+ if (m_errorReporter.errors().empty())
+ throw; // Something is weird here, rather throw again.
+ noErrors = false;
}
if (noErrors)
diff --git a/libsolidity/interface/ErrorReporter.cpp b/libsolidity/interface/ErrorReporter.cpp
index e6171756..368e25e0 100644
--- a/libsolidity/interface/ErrorReporter.cpp
+++ b/libsolidity/interface/ErrorReporter.cpp
@@ -61,6 +61,9 @@ void ErrorReporter::warning(
void ErrorReporter::error(Error::Type _type, SourceLocation const& _location, string const& _description)
{
+ if (checkForExcessiveErrors(_type))
+ return;
+
auto err = make_shared<Error>(_type);
*err <<
errinfo_sourceLocation(_location) <<
@@ -71,6 +74,9 @@ void ErrorReporter::error(Error::Type _type, SourceLocation const& _location, st
void ErrorReporter::error(Error::Type _type, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, string const& _description)
{
+ if (checkForExcessiveErrors(_type))
+ return;
+
auto err = make_shared<Error>(_type);
*err <<
errinfo_sourceLocation(_location) <<
@@ -80,6 +86,37 @@ void ErrorReporter::error(Error::Type _type, SourceLocation const& _location, Se
m_errorList.push_back(err);
}
+bool ErrorReporter::checkForExcessiveErrors(Error::Type _type)
+{
+ if (_type == Error::Type::Warning)
+ {
+ m_warningCount++;
+
+ if (m_warningCount == c_maxWarningsAllowed)
+ {
+ auto err = make_shared<Error>(Error::Type::Warning);
+ *err << errinfo_comment("There are more than 256 warnings. Ignoring the rest.");
+ m_errorList.push_back(err);
+ }
+
+ if (m_warningCount >= c_maxWarningsAllowed)
+ return true;
+ }
+ else
+ {
+ m_errorCount++;
+
+ if (m_errorCount > c_maxErrorsAllowed)
+ {
+ auto err = make_shared<Error>(Error::Type::Warning);
+ *err << errinfo_comment("There are more than 256 errors. Aborting.");
+ m_errorList.push_back(err);
+ BOOST_THROW_EXCEPTION(FatalError());
+ }
+ }
+
+ return false;
+}
void ErrorReporter::fatalError(Error::Type _type, SourceLocation const& _location, string const& _description)
{
diff --git a/libsolidity/interface/ErrorReporter.h b/libsolidity/interface/ErrorReporter.h
index a87db21d..d1a0030f 100644
--- a/libsolidity/interface/ErrorReporter.h
+++ b/libsolidity/interface/ErrorReporter.h
@@ -102,7 +102,16 @@ private:
SourceLocation const& _location = SourceLocation(),
std::string const& _description = std::string());
+ // @returns true if error shouldn't be stored
+ bool checkForExcessiveErrors(Error::Type _type);
+
ErrorList& m_errorList;
+
+ unsigned m_errorCount = 0;
+ unsigned m_warningCount = 0;
+
+ const unsigned c_maxWarningsAllowed = 256;
+ const unsigned c_maxErrorsAllowed = 256;
};
diff --git a/libsolidity/interface/GasEstimator.cpp b/libsolidity/interface/GasEstimator.cpp
index 2139395f..a496cc21 100644
--- a/libsolidity/interface/GasEstimator.cpp
+++ b/libsolidity/interface/GasEstimator.cpp
@@ -136,12 +136,19 @@ GasEstimator::GasConsumption GasEstimator::functionalEstimation(
ExpressionClasses& classes = state->expressionClasses();
using Id = ExpressionClasses::Id;
using Ids = vector<Id>;
+ // div(calldataload(0), 1 << 224) equals to hashValue
Id hashValue = classes.find(u256(FixedHash<4>::Arith(FixedHash<4>(dev::keccak256(_signature)))));
Id calldata = classes.find(Instruction::CALLDATALOAD, Ids{classes.find(u256(0))});
classes.forceEqual(hashValue, Instruction::DIV, Ids{
calldata,
- classes.find(u256(1) << (8 * 28))
+ classes.find(u256(1) << 224)
});
+ // lt(calldatasize(), 4) equals to 0 (ignore the shortcut for fallback functions)
+ classes.forceEqual(
+ classes.find(u256(0)),
+ Instruction::LT,
+ Ids{classes.find(Instruction::CALLDATASIZE), classes.find(u256(4))}
+ );
}
PathGasMeter meter(_items, m_evmVersion);
diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp
index 8c97f55f..2d8ca7d3 100644
--- a/libsolidity/parsing/Parser.cpp
+++ b/libsolidity/parsing/Parser.cpp
@@ -238,7 +238,10 @@ ASTPointer<ContractDefinition> Parser::parseContractDefinition(Token::Value _exp
Token::Value currentTokenValue = m_scanner->currentToken();
if (currentTokenValue == Token::RBrace)
break;
- else if (currentTokenValue == Token::Function)
+ else if (
+ currentTokenValue == Token::Function ||
+ (currentTokenValue == Token::Identifier && m_scanner->currentLiteral() == "constructor")
+ )
// This can be a function or a state variable of function type (especially
// complicated to distinguish fallback function from function type state variable)
subNodes.push_back(parseFunctionDefinitionOrFunctionTypeStateVariable(name.get()));
@@ -283,17 +286,17 @@ ASTPointer<InheritanceSpecifier> Parser::parseInheritanceSpecifier()
RecursionGuard recursionGuard(*this);
ASTNodeFactory nodeFactory(*this);
ASTPointer<UserDefinedTypeName> name(parseUserDefinedTypeName());
- vector<ASTPointer<Expression>> arguments;
+ unique_ptr<vector<ASTPointer<Expression>>> arguments;
if (m_scanner->currentToken() == Token::LParen)
{
m_scanner->next();
- arguments = parseFunctionCallListArguments();
+ arguments.reset(new vector<ASTPointer<Expression>>(parseFunctionCallListArguments()));
nodeFactory.markEndPosition();
expectToken(Token::RParen);
}
else
nodeFactory.setEndPositionFromNode(name);
- return nodeFactory.createNode<InheritanceSpecifier>(name, arguments);
+ return nodeFactory.createNode<InheritanceSpecifier>(name, std::move(arguments));
}
Declaration::Visibility Parser::parseVisibilitySpecifier(Token::Value _token)
@@ -329,15 +332,31 @@ StateMutability Parser::parseStateMutability(Token::Value _token)
return stateMutability;
}
-Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(bool _forceEmptyName, bool _allowModifiers)
+Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(
+ bool _forceEmptyName,
+ bool _allowModifiers,
+ ASTString const* _contractName
+)
{
RecursionGuard recursionGuard(*this);
FunctionHeaderParserResult result;
- expectToken(Token::Function);
- if (_forceEmptyName || m_scanner->currentToken() == Token::LParen)
- result.name = make_shared<ASTString>(); // anonymous function
+
+ result.isConstructor = false;
+
+ if (m_scanner->currentToken() == Token::Identifier && m_scanner->currentLiteral() == "constructor")
+ result.isConstructor = true;
+ else if (m_scanner->currentToken() != Token::Function)
+ solAssert(false, "Function or constructor expected.");
+ m_scanner->next();
+
+ if (result.isConstructor || _forceEmptyName || m_scanner->currentToken() == Token::LParen)
+ result.name = make_shared<ASTString>();
else
result.name = expectIdentifierToken();
+
+ if (!result.name->empty() && _contractName && *result.name == *_contractName)
+ result.isConstructor = true;
+
VarDeclParserOptions options;
options.allowLocationSpecifier = true;
result.parameters = parseParameterList(options);
@@ -346,12 +365,13 @@ Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(bool _forceEmptyN
Token::Value token = m_scanner->currentToken();
if (_allowModifiers && token == Token::Identifier)
{
- // This can either be a modifier (function declaration) or the name of the
- // variable (function type name plus variable).
- if (
+ // If the name is empty (and this is not a constructor),
+ // then this can either be a modifier (fallback function declaration)
+ // or the name of the state variable (function type name plus variable).
+ if ((result.name->empty() && !result.isConstructor) && (
m_scanner->peekNextToken() == Token::Semicolon ||
m_scanner->peekNextToken() == Token::Assign
- )
+ ))
// Variable declaration, break here.
break;
else
@@ -361,6 +381,14 @@ Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(bool _forceEmptyN
{
if (result.visibility != Declaration::Visibility::Default)
{
+ // There is the special case of a public state variable of function type.
+ // Detect this and return early.
+ if (
+ (result.visibility == Declaration::Visibility::External || result.visibility == Declaration::Visibility::Internal) &&
+ result.modifiers.empty() &&
+ (result.name->empty() && !result.isConstructor)
+ )
+ break;
parserError(string(
"Visibility already specified as \"" +
Declaration::visibilityToString(result.visibility) +
@@ -407,9 +435,10 @@ ASTPointer<ASTNode> Parser::parseFunctionDefinitionOrFunctionTypeStateVariable(A
if (m_scanner->currentCommentLiteral() != "")
docstring = make_shared<ASTString>(m_scanner->currentCommentLiteral());
- FunctionHeaderParserResult header = parseFunctionHeader(false, true);
+ FunctionHeaderParserResult header = parseFunctionHeader(false, true, _contractName);
if (
+ header.isConstructor ||
!header.modifiers.empty() ||
!header.name->empty() ||
m_scanner->currentToken() == Token::Semicolon ||
@@ -426,12 +455,11 @@ ASTPointer<ASTNode> Parser::parseFunctionDefinitionOrFunctionTypeStateVariable(A
}
else
m_scanner->next(); // just consume the ';'
- bool const c_isConstructor = (_contractName && *header.name == *_contractName);
return nodeFactory.createNode<FunctionDefinition>(
header.name,
header.visibility,
header.stateMutability,
- c_isConstructor,
+ header.isConstructor,
docstring,
header.parameters,
header.modifiers,
@@ -683,17 +711,17 @@ ASTPointer<ModifierInvocation> Parser::parseModifierInvocation()
RecursionGuard recursionGuard(*this);
ASTNodeFactory nodeFactory(*this);
ASTPointer<Identifier> name(parseIdentifier());
- vector<ASTPointer<Expression>> arguments;
+ unique_ptr<vector<ASTPointer<Expression>>> arguments;
if (m_scanner->currentToken() == Token::LParen)
{
m_scanner->next();
- arguments = parseFunctionCallListArguments();
+ arguments.reset(new vector<ASTPointer<Expression>>(parseFunctionCallListArguments()));
nodeFactory.markEndPosition();
expectToken(Token::RParen);
}
else
nodeFactory.setEndPositionFromNode(name);
- return nodeFactory.createNode<ModifierInvocation>(name, arguments);
+ return nodeFactory.createNode<ModifierInvocation>(name, move(arguments));
}
ASTPointer<Identifier> Parser::parseIdentifier()
@@ -776,6 +804,7 @@ ASTPointer<FunctionTypeName> Parser::parseFunctionType()
RecursionGuard recursionGuard(*this);
ASTNodeFactory nodeFactory(*this);
FunctionHeaderParserResult header = parseFunctionHeader(true, false);
+ solAssert(!header.isConstructor, "Tried to parse type as constructor.");
return nodeFactory.createNode<FunctionTypeName>(
header.parameters,
header.returnParameters,
diff --git a/libsolidity/parsing/Parser.h b/libsolidity/parsing/Parser.h
index 3f780af9..eb120a61 100644
--- a/libsolidity/parsing/Parser.h
+++ b/libsolidity/parsing/Parser.h
@@ -56,6 +56,7 @@ private:
/// This struct is shared for parsing a function header and a function type.
struct FunctionHeaderParserResult
{
+ bool isConstructor;
ASTPointer<ASTString> name;
ASTPointer<ParameterList> parameters;
ASTPointer<ParameterList> returnParameters;
@@ -73,7 +74,11 @@ private:
ASTPointer<InheritanceSpecifier> parseInheritanceSpecifier();
Declaration::Visibility parseVisibilitySpecifier(Token::Value _token);
StateMutability parseStateMutability(Token::Value _token);
- FunctionHeaderParserResult parseFunctionHeader(bool _forceEmptyName, bool _allowModifiers);
+ FunctionHeaderParserResult parseFunctionHeader(
+ bool _forceEmptyName,
+ bool _allowModifiers,
+ ASTString const* _contractName = nullptr
+ );
ASTPointer<ASTNode> parseFunctionDefinitionOrFunctionTypeStateVariable(ASTString const* _contractName);
ASTPointer<FunctionDefinition> parseFunctionDefinition(ASTString const* _contractName);
ASTPointer<StructDefinition> parseStructDefinition();
diff --git a/libsolidity/parsing/Token.cpp b/libsolidity/parsing/Token.cpp
index 9cec0303..5ce74316 100644
--- a/libsolidity/parsing/Token.cpp
+++ b/libsolidity/parsing/Token.cpp
@@ -53,7 +53,7 @@ namespace solidity
void ElementaryTypeNameToken::assertDetails(Token::Value _baseType, unsigned const& _first, unsigned const& _second)
{
- solAssert(Token::isElementaryTypeName(_baseType), "");
+ solAssert(Token::isElementaryTypeName(_baseType), "Expected elementary type name: " + string(Token::toString(_baseType)));
if (_baseType == Token::BytesM)
{
solAssert(_second == 0, "There should not be a second size argument to type bytesM.");
diff --git a/scripts/cpp-ethereum/build.sh b/scripts/cpp-ethereum/build.sh
new file mode 100755
index 00000000..23ed1290
--- /dev/null
+++ b/scripts/cpp-ethereum/build.sh
@@ -0,0 +1,17 @@
+#!/usr/bin/env sh
+
+# Script to build the eth binary from latest develop
+# for ubuntu trusty and ubuntu artful.
+# Requires docker.
+
+set -e
+
+REPO_ROOT="$(dirname "$0")"/../..
+
+for rel in artful trusty
+do
+ docker build -t eth_$rel -f "$REPO_ROOT"/scripts/cpp-ethereum/eth_$rel.docker .
+ tmp_container=$(docker create eth_$rel sh)
+ echo "Built eth ($rel) at $REPO_ROOT/build/eth_$rel"
+ docker cp ${tmp_container}:/build/eth/eth "$REPO_ROOT"/build/eth_$rel
+done \ No newline at end of file
diff --git a/scripts/cpp-ethereum/eth_artful.docker b/scripts/cpp-ethereum/eth_artful.docker
new file mode 100644
index 00000000..7ce9faae
--- /dev/null
+++ b/scripts/cpp-ethereum/eth_artful.docker
@@ -0,0 +1,7 @@
+FROM ubuntu:artful
+
+RUN apt update
+RUN apt -y install libleveldb-dev cmake g++ git
+RUN git clone --recursive https://github.com/ethereum/cpp-ethereum --branch develop --single-branch --depth 1
+RUN mkdir /build && cd /build && cmake /cpp-ethereum -DCMAKE_BUILD_TYPE=RelWithDebInfo -DTOOLS=Off -DTESTS=Off
+RUN cd /build && make eth
diff --git a/scripts/cpp-ethereum/eth_trusty.docker b/scripts/cpp-ethereum/eth_trusty.docker
new file mode 100644
index 00000000..5cfb59f7
--- /dev/null
+++ b/scripts/cpp-ethereum/eth_trusty.docker
@@ -0,0 +1,13 @@
+FROM ubuntu:trusty
+
+RUN apt-get update
+RUN apt-get -y install software-properties-common python-software-properties
+RUN add-apt-repository ppa:ubuntu-toolchain-r/test
+RUN apt-get update
+RUN apt-get -y install gcc libleveldb-dev git curl make gcc-7 g++-7
+RUN ln -sf /usr/bin/gcc-7 /usr/bin/gcc
+RUN ln -sf /usr/bin/g++-7 /usr/bin/g++
+RUN git clone --recursive https://github.com/ethereum/cpp-ethereum --branch develop --single-branch --depth 1
+RUN ./cpp-ethereum/scripts/install_cmake.sh
+RUN mkdir /build && cd /build && ~/.local/bin/cmake /cpp-ethereum -DCMAKE_BUILD_TYPE=RelWithDebInfo -DTOOLS=Off -DTESTS=Off
+RUN cd /build && make eth
diff --git a/scripts/tests.sh b/scripts/tests.sh
index 37ffafc2..542c932a 100755
--- a/scripts/tests.sh
+++ b/scripts/tests.sh
@@ -61,13 +61,13 @@ function download_eth()
mkdir -p /tmp/test
if grep -i trusty /etc/lsb-release >/dev/null 2>&1
then
- # built from 1ecff3cac12f0fbbeea3e645f331d5ac026b24d3 at 2018-03-06
- ETH_BINARY=eth_byzantium_trusty
- ETH_HASH="5432ea81c150e8a3547615bf597cd6dce9e1e27b"
+ # built from 5ac09111bd0b6518365fe956e1bdb97a2db82af1 at 2018-04-05
+ ETH_BINARY=eth_2018-04-05_trusty
+ ETH_HASH="1e5e178b005e5b51f9d347df4452875ba9b53cc6"
else
- # built from ?? at 2018-02-13 ?
- ETH_BINARY=eth_byzantium_artful
- ETH_HASH="e527dd3e3dc17b983529dd7dcfb74a0d3a5aed4e"
+ # built from 5ac09111bd0b6518365fe956e1bdb97a2db82af1 at 2018-04-05
+ ETH_BINARY=eth_2018-04-05_artful
+ ETH_HASH="eb2d0df022753bb2b442ba73e565a9babf6828d6"
fi
wget -q -O /tmp/test/eth https://github.com/ethereum/cpp-ethereum/releases/download/solidityTester/$ETH_BINARY
test "$(shasum /tmp/test/eth)" = "$ETH_HASH /tmp/test/eth"
@@ -99,11 +99,18 @@ then
progress=""
fi
+EVM_VERSIONS="homestead byzantium"
+
+if [ "$CIRCLECI" ] || [ -z "$CI" ]
+then
+EVM_VERSIONS+=" constantinople"
+fi
+
# And then run the Solidity unit-tests in the matrix combination of optimizer / no optimizer
# and homestead / byzantium VM, # pointing to that IPC endpoint.
for optimize in "" "--optimize"
do
- for vm in homestead byzantium
+ for vm in $EVM_VERSIONS
do
echo "--> Running tests using "$optimize" --evm-version "$vm"..."
log=""
diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp
index 8f81e799..bd5e2eb1 100644
--- a/solc/CommandLineInterface.cpp
+++ b/solc/CommandLineInterface.cpp
@@ -636,7 +636,7 @@ Allowed options)",
(g_argNatspecUser.c_str(), "Natspec user documentation of all contracts.")
(g_argNatspecDev.c_str(), "Natspec developer documentation of all contracts.")
(g_argMetadata.c_str(), "Combined Metadata JSON whose Swarm hash is stored on-chain.")
- (g_argFormal.c_str(), "Translated source suitable for formal analysis.");
+ (g_argFormal.c_str(), "Translated source suitable for formal analysis. (Deprecated)");
desc.add(outputComponents);
po::options_description allOptions = desc;
@@ -700,7 +700,7 @@ bool CommandLineInterface::processInput()
try
{
auto path = boost::filesystem::path(_path);
- auto canonicalPath = boost::filesystem::canonical(path);
+ auto canonicalPath = weaklyCanonicalFilesystemPath(path);
bool isAllowed = false;
for (auto const& allowedDir: m_allowedDirectories)
{
@@ -716,16 +716,16 @@ bool CommandLineInterface::processInput()
}
if (!isAllowed)
return ReadCallback::Result{false, "File outside of allowed directories."};
- else if (!boost::filesystem::exists(path))
+
+ if (!boost::filesystem::exists(canonicalPath))
return ReadCallback::Result{false, "File not found."};
- else if (!boost::filesystem::is_regular_file(canonicalPath))
+
+ if (!boost::filesystem::is_regular_file(canonicalPath))
return ReadCallback::Result{false, "Not a valid file."};
- else
- {
- auto contents = dev::readFileAsString(canonicalPath.string());
- m_sourceCodes[path.string()] = contents;
- return ReadCallback::Result{true, contents};
- }
+
+ auto contents = dev::readFileAsString(canonicalPath.string());
+ m_sourceCodes[path.string()] = contents;
+ return ReadCallback::Result{true, contents};
}
catch (Exception const& _exception)
{
diff --git a/std/StandardToken.sol b/std/StandardToken.sol
index 1b218d67..5afc9747 100644
--- a/std/StandardToken.sol
+++ b/std/StandardToken.sol
@@ -1,4 +1,4 @@
-pragma solidity ^0.4.0;
+pragma solidity >0.4.21;
import "./Token.sol";
@@ -8,7 +8,7 @@ contract StandardToken is Token {
mapping (address =>
mapping (address => uint256)) m_allowance;
- function StandardToken(address _initialOwner, uint256 _supply) public {
+ constructor(address _initialOwner, uint256 _supply) public {
supply = _supply;
balance[_initialOwner] = _supply;
}
diff --git a/std/owned.sol b/std/owned.sol
index ee9860d3..8e1d5917 100644
--- a/std/owned.sol
+++ b/std/owned.sol
@@ -1,4 +1,4 @@
-pragma solidity ^0.4.0;
+pragma solidity >0.4.21;
contract owned {
address owner;
@@ -9,7 +9,7 @@ contract owned {
}
}
- function owned() public {
+ constructor() public {
owner = msg.sender;
}
}
diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp
index 03b1341c..f4eae865 100644
--- a/test/RPCSession.cpp
+++ b/test/RPCSession.cpp
@@ -226,6 +226,8 @@ void RPCSession::test_setChainParams(vector<string> const& _accounts)
forks += "\"EIP158ForkBlock\": \"0x00\",\n";
if (test::Options::get().evmVersion() >= solidity::EVMVersion::byzantium())
forks += "\"byzantiumForkBlock\": \"0x00\",\n";
+ if (test::Options::get().evmVersion() >= solidity::EVMVersion::constantinople())
+ forks += "\"constantinopleForkBlock\": \"0x00\",\n";
static string const c_configString = R"(
{
"sealEngine": "NoProof",
@@ -337,7 +339,9 @@ Json::Value RPCSession::rpcCall(string const& _methodName, vector<string> const&
BOOST_TEST_MESSAGE("Reply: " + reply);
Json::Value result;
- BOOST_REQUIRE(jsonParseStrict(reply, result));
+ string errorMsg;
+ if (!jsonParseStrict(reply, result, &errorMsg))
+ BOOST_REQUIRE_MESSAGE(false, errorMsg);
if (result.isMember("error"))
{
diff --git a/test/libevmasm/Optimiser.cpp b/test/libevmasm/Optimiser.cpp
index 28f6b8c0..089be45d 100644
--- a/test/libevmasm/Optimiser.cpp
+++ b/test/libevmasm/Optimiser.cpp
@@ -858,6 +858,115 @@ BOOST_AUTO_TEST_CASE(peephole_pop_calldatasize)
BOOST_CHECK(items.empty());
}
+BOOST_AUTO_TEST_CASE(peephole_commutative_swap1)
+{
+ vector<Instruction> ops{
+ Instruction::ADD,
+ Instruction::MUL,
+ Instruction::EQ,
+ Instruction::AND,
+ Instruction::OR,
+ Instruction::XOR
+ };
+ for (Instruction const op: ops)
+ {
+ AssemblyItems items{
+ u256(1),
+ u256(2),
+ Instruction::SWAP1,
+ op,
+ u256(4),
+ u256(5)
+ };
+ AssemblyItems expectation{
+ u256(1),
+ u256(2),
+ op,
+ u256(4),
+ u256(5)
+ };
+ PeepholeOptimiser peepOpt(items);
+ BOOST_REQUIRE(peepOpt.optimise());
+ BOOST_CHECK_EQUAL_COLLECTIONS(
+ items.begin(), items.end(),
+ expectation.begin(), expectation.end()
+ );
+ }
+}
+
+BOOST_AUTO_TEST_CASE(peephole_noncommutative_swap1)
+{
+ // NOTE: not comprehensive
+ vector<Instruction> ops{
+ Instruction::SUB,
+ Instruction::DIV,
+ Instruction::SDIV,
+ Instruction::MOD,
+ Instruction::SMOD,
+ Instruction::EXP
+ };
+ for (Instruction const op: ops)
+ {
+ AssemblyItems items{
+ u256(1),
+ u256(2),
+ Instruction::SWAP1,
+ op,
+ u256(4),
+ u256(5)
+ };
+ AssemblyItems expectation{
+ u256(1),
+ u256(2),
+ Instruction::SWAP1,
+ op,
+ u256(4),
+ u256(5)
+ };
+ PeepholeOptimiser peepOpt(items);
+ BOOST_REQUIRE(!peepOpt.optimise());
+ BOOST_CHECK_EQUAL_COLLECTIONS(
+ items.begin(), items.end(),
+ expectation.begin(), expectation.end()
+ );
+ }
+}
+
+BOOST_AUTO_TEST_CASE(peephole_swap_comparison)
+{
+ map<Instruction, Instruction> swappableOps{
+ { Instruction::LT, Instruction::GT },
+ { Instruction::GT, Instruction::LT },
+ { Instruction::SLT, Instruction::SGT },
+ { Instruction::SGT, Instruction::SLT }
+ };
+
+ for (auto const& op: swappableOps)
+ {
+ AssemblyItems items{
+ u256(1),
+ u256(2),
+ Instruction::SWAP1,
+ op.first,
+ u256(4),
+ u256(5)
+ };
+ AssemblyItems expectation{
+ u256(1),
+ u256(2),
+ op.second,
+ u256(4),
+ u256(5)
+ };
+ PeepholeOptimiser peepOpt(items);
+ BOOST_REQUIRE(peepOpt.optimise());
+ BOOST_CHECK_EQUAL_COLLECTIONS(
+ items.begin(), items.end(),
+ expectation.begin(), expectation.end()
+ );
+ }
+}
+
BOOST_AUTO_TEST_CASE(jumpdest_removal)
{
AssemblyItems items{
diff --git a/test/libjulia/CommonSubexpression.cpp b/test/libjulia/CommonSubexpression.cpp
new file mode 100644
index 00000000..8a575c48
--- /dev/null
+++ b/test/libjulia/CommonSubexpression.cpp
@@ -0,0 +1,102 @@
+/*
+ This file is part of solidity.
+
+ solidity is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ solidity is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with solidity. If not, see <http://www.gnu.org/licenses/>.
+*/
+/**
+ * Unit tests for the common subexpression eliminator optimizer stage.
+ */
+
+#include <test/libjulia/Common.h>
+
+#include <libjulia/optimiser/CommonSubexpressionEliminator.h>
+
+#include <libsolidity/inlineasm/AsmPrinter.h>
+
+#include <boost/test/unit_test.hpp>
+
+#include <boost/range/adaptors.hpp>
+#include <boost/algorithm/string/join.hpp>
+
+using namespace std;
+using namespace dev;
+using namespace dev::julia;
+using namespace dev::julia::test;
+using namespace dev::solidity;
+
+
+#define CHECK(_original, _expectation)\
+do\
+{\
+ assembly::AsmPrinter p;\
+ Block b = disambiguate(_original, false);\
+ (CommonSubexpressionEliminator{})(b);\
+ string result = p(b);\
+ BOOST_CHECK_EQUAL(result, format(_expectation, false));\
+}\
+while(false)
+
+BOOST_AUTO_TEST_SUITE(IuliaCSE)
+
+BOOST_AUTO_TEST_CASE(smoke_test)
+{
+ CHECK("{ }", "{ }");
+}
+
+BOOST_AUTO_TEST_CASE(trivial)
+{
+ CHECK(
+ "{ let a := mul(1, codesize()) let b := mul(1, codesize()) }",
+ "{ let a := mul(1, codesize()) let b := a }"
+ );
+}
+
+BOOST_AUTO_TEST_CASE(non_movable_instr)
+{
+ CHECK(
+ "{ let a := mload(1) let b := mload(1) }",
+ "{ let a := mload(1) let b := mload(1) }"
+ );
+}
+
+BOOST_AUTO_TEST_CASE(non_movable_instr2)
+{
+ CHECK(
+ "{ let a := gas() let b := gas() }",
+ "{ let a := gas() let b := gas() }"
+ );
+}
+
+BOOST_AUTO_TEST_CASE(branches_if)
+{
+ CHECK(
+ "{ let b := 1 if b { b := 1 } let c := 1 }",
+ "{ let b := 1 if b { b := b } let c := 1 }"
+ );
+}
+
+BOOST_AUTO_TEST_CASE(branches_for)
+{
+ CHECK(
+ "{ let a := 1 let b := codesize()"
+ "for { } lt(1, codesize()) { mstore(1, codesize()) a := add(a, codesize()) }"
+ "{ mstore(1, codesize()) } mstore(1, codesize()) }",
+
+ "{ let a := 1 let b := codesize()"
+ "for { } lt(1, b) { mstore(1, b) a := add(a, b) }"
+ "{ mstore(1, b) } mstore(1, b) }"
+ );
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/libsolidity/AnalysisFramework.cpp b/test/libsolidity/AnalysisFramework.cpp
index 4538757d..72b86767 100644
--- a/test/libsolidity/AnalysisFramework.cpp
+++ b/test/libsolidity/AnalysisFramework.cpp
@@ -56,12 +56,23 @@ AnalysisFramework::parseAnalyseAndReturnError(
m_compiler.analyze();
+ ErrorList errors = filterErrors(m_compiler.errors(), _reportWarnings);
+ if (errors.size() > 1 && !_allowMultipleErrors)
+ BOOST_FAIL("Multiple errors found: " + formatErrors());
+
+ return make_pair(&m_compiler.ast(""), std::move(errors));
+}
+
+ErrorList AnalysisFramework::filterErrors(ErrorList const& _errorList, bool _includeWarnings) const
+{
ErrorList errors;
- for (auto const& currentError: m_compiler.errors())
+ for (auto const& currentError: _errorList)
{
solAssert(currentError->comment(), "");
if (currentError->type() == Error::Type::Warning)
{
+ if (!_includeWarnings)
+ continue;
bool ignoreWarning = false;
for (auto const& filter: m_warningsToFilter)
if (currentError->comment()->find(filter) == 0)
@@ -73,17 +84,10 @@ AnalysisFramework::parseAnalyseAndReturnError(
continue;
}
- if (_reportWarnings || (currentError->type() != Error::Type::Warning))
- {
- if (!_allowMultipleErrors && !errors.empty())
- {
- BOOST_FAIL("Multiple errors found: " + formatErrors());
- }
- errors.emplace_back(std::move(currentError));
- }
+ errors.emplace_back(currentError);
}
- return make_pair(&m_compiler.ast(""), errors);
+ return errors;
}
SourceUnit const* AnalysisFramework::parseAndAnalyse(string const& _source)
@@ -110,7 +114,7 @@ ErrorList AnalysisFramework::expectError(std::string const& _source, bool _warni
return sourceAndErrors.second;
}
-string AnalysisFramework::formatErrors()
+string AnalysisFramework::formatErrors() const
{
string message;
for (auto const& error: m_compiler.errors())
@@ -118,7 +122,7 @@ string AnalysisFramework::formatErrors()
return message;
}
-string AnalysisFramework::formatError(Error const& _error)
+string AnalysisFramework::formatError(Error const& _error) const
{
return SourceReferenceFormatter::formatExceptionInformation(
_error,
diff --git a/test/libsolidity/AnalysisFramework.h b/test/libsolidity/AnalysisFramework.h
index 6ecf4a5a..05490a42 100644
--- a/test/libsolidity/AnalysisFramework.h
+++ b/test/libsolidity/AnalysisFramework.h
@@ -57,8 +57,8 @@ protected:
bool success(std::string const& _source);
ErrorList expectError(std::string const& _source, bool _warning = false, bool _allowMultiple = false);
- std::string formatErrors();
- std::string formatError(Error const& _error);
+ std::string formatErrors() const;
+ std::string formatError(Error const& _error) const;
static ContractDefinition const* retrieveContractByName(SourceUnit const& _source, std::string const& _name);
static FunctionTypePointer retrieveFunctionBySignature(
@@ -66,6 +66,9 @@ protected:
std::string const& _signature
);
+ // filter out the warnings in m_warningsToFilter or all warnings if _includeWarnings is false
+ ErrorList filterErrors(ErrorList const& _errorList, bool _includeWarnings) const;
+
std::vector<std::string> m_warningsToFilter = {"This is a pre-release compiler version"};
dev::solidity::CompilerStack m_compiler;
};
diff --git a/test/libsolidity/FormattedScope.h b/test/libsolidity/FormattedScope.h
index 78560848..923404f0 100644
--- a/test/libsolidity/FormattedScope.h
+++ b/test/libsolidity/FormattedScope.h
@@ -38,6 +38,8 @@ static constexpr char const* GREEN = "\033[1;32m";
static constexpr char const* YELLOW = "\033[1;33m";
static constexpr char const* CYAN = "\033[1;36m";
static constexpr char const* BOLD = "\033[1m";
+static constexpr char const* RED_BACKGROUND = "\033[48;5;160m";
+static constexpr char const* ORANGE_BACKGROUND = "\033[48;5;166m";
static constexpr char const* INVERSE = "\033[7m";
}
diff --git a/test/libsolidity/GasMeter.cpp b/test/libsolidity/GasMeter.cpp
index fd2017f9..0d66456c 100644
--- a/test/libsolidity/GasMeter.cpp
+++ b/test/libsolidity/GasMeter.cpp
@@ -294,6 +294,19 @@ BOOST_AUTO_TEST_CASE(extcodesize_gas)
testRunTimeGas("f()", vector<bytes>{encodeArgs()});
}
+BOOST_AUTO_TEST_CASE(regular_functions_exclude_fallback)
+{
+ // A bug in the estimator caused the costs for a specific function
+ // to always include the costs for the fallback.
+ char const* sourceCode = R"(
+ contract A {
+ uint public x;
+ function() { x = 2; }
+ }
+ )";
+ testCreationTimeGas(sourceCode);
+ testRunTimeGas("x()", vector<bytes>{encodeArgs()});
+}
BOOST_AUTO_TEST_SUITE_END()
}
diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp
index 34ca33e3..0ced1792 100644
--- a/test/libsolidity/InlineAssembly.cpp
+++ b/test/libsolidity/InlineAssembly.cpp
@@ -783,6 +783,8 @@ BOOST_AUTO_TEST_CASE(shift)
BOOST_AUTO_TEST_CASE(shift_constantinople_warning)
{
+ if (dev::test::Options::get().evmVersion().hasBitwiseShifting())
+ return;
CHECK_PARSE_WARNING("{ pop(shl(10, 32)) }", Warning, "The \"shl\" instruction is only available for Constantinople-compatible VMs.");
CHECK_PARSE_WARNING("{ pop(shr(10, 32)) }", Warning, "The \"shr\" instruction is only available for Constantinople-compatible VMs.");
CHECK_PARSE_WARNING("{ pop(sar(10, 32)) }", Warning, "The \"sar\" instruction is only available for Constantinople-compatible VMs.");
diff --git a/test/libsolidity/JSONCompiler.cpp b/test/libsolidity/JSONCompiler.cpp
index aed0a370..cdcc22a6 100644
--- a/test/libsolidity/JSONCompiler.cpp
+++ b/test/libsolidity/JSONCompiler.cpp
@@ -111,12 +111,12 @@ BOOST_AUTO_TEST_CASE(basic_compilation)
BOOST_CHECK(contract["bytecode"].isString());
BOOST_CHECK_EQUAL(
dev::test::bytecodeSansMetadata(contract["bytecode"].asString()),
- "60606040523415600e57600080fd5b603580601b6000396000f3006060604052600080fd00"
+ "60806040523415600e57600080fd5b603580601b6000396000f3006080604052600080fd00"
);
BOOST_CHECK(contract["runtimeBytecode"].isString());
BOOST_CHECK_EQUAL(
dev::test::bytecodeSansMetadata(contract["runtimeBytecode"].asString()),
- "6060604052600080fd00"
+ "6080604052600080fd00"
);
BOOST_CHECK(contract["functionHashes"].isObject());
BOOST_CHECK(contract["gasEstimates"].isObject());
@@ -153,12 +153,12 @@ BOOST_AUTO_TEST_CASE(single_compilation)
BOOST_CHECK(contract["bytecode"].isString());
BOOST_CHECK_EQUAL(
dev::test::bytecodeSansMetadata(contract["bytecode"].asString()),
- "60606040523415600e57600080fd5b603580601b6000396000f3006060604052600080fd00"
+ "60806040523415600e57600080fd5b603580601b6000396000f3006080604052600080fd00"
);
BOOST_CHECK(contract["runtimeBytecode"].isString());
BOOST_CHECK_EQUAL(
dev::test::bytecodeSansMetadata(contract["runtimeBytecode"].asString()),
- "6060604052600080fd00"
+ "6080604052600080fd00"
);
BOOST_CHECK(contract["functionHashes"].isObject());
BOOST_CHECK(contract["gasEstimates"].isObject());
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 38d3ce4d..39f4b03e 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -4884,6 +4884,48 @@ BOOST_AUTO_TEST_CASE(array_push)
ABI_CHECK(callContractFunction("test()"), encodeArgs(5, 4, 3, 3));
}
+BOOST_AUTO_TEST_CASE(array_push_struct)
+{
+ char const* sourceCode = R"(
+ contract c {
+ struct S { uint16 a; uint16 b; uint16[3] c; uint16[] d; }
+ S[] data;
+ function test() returns (uint16, uint16, uint16, uint16) {
+ S memory s;
+ s.a = 2;
+ s.b = 3;
+ s.c[2] = 4;
+ s.d = new uint16[](4);
+ s.d[2] = 5;
+ data.push(s);
+ return (data[0].a, data[0].b, data[0].c[2], data[0].d[2]);
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ ABI_CHECK(callContractFunction("test()"), encodeArgs(2, 3, 4, 5));
+}
+
+BOOST_AUTO_TEST_CASE(array_push_packed_array)
+{
+ char const* sourceCode = R"(
+ contract c {
+ uint80[] x;
+ function test() returns (uint80, uint80, uint80, uint80) {
+ x.push(1);
+ x.push(2);
+ x.push(3);
+ x.push(4);
+ x.push(5);
+ x.length = 4;
+ return (x[0], x[1], x[2], x[3]);
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ ABI_CHECK(callContractFunction("test()"), encodeArgs(1, 2, 3, 4));
+}
+
BOOST_AUTO_TEST_CASE(byte_array_push)
{
char const* sourceCode = R"(
@@ -4904,6 +4946,29 @@ BOOST_AUTO_TEST_CASE(byte_array_push)
ABI_CHECK(callContractFunction("test()"), encodeArgs(false));
}
+BOOST_AUTO_TEST_CASE(byte_array_push_transition)
+{
+ // Tests transition between short and long encoding
+ char const* sourceCode = R"(
+ contract c {
+ bytes data;
+ function test() returns (uint) {
+ for (uint i = 1; i < 40; i++)
+ {
+ data.push(byte(i));
+ if (data.length != i) return 0x1000 + i;
+ if (data[data.length - 1] != byte(i)) return i;
+ }
+ for (i = 1; i < 40; i++)
+ if (data[i - 1] != byte(i)) return 0x1000000 + i;
+ return 0;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ ABI_CHECK(callContractFunction("test()"), encodeArgs(0));
+}
+
BOOST_AUTO_TEST_CASE(external_array_args)
{
char const* sourceCode = R"(
@@ -5126,7 +5191,7 @@ BOOST_AUTO_TEST_CASE(pass_dynamic_arguments_to_the_base)
}
uint public m_i;
}
- contract Derived is Base(2) {
+ contract Derived is Base {
function Derived(uint i) Base(i)
{}
}
@@ -5146,10 +5211,10 @@ BOOST_AUTO_TEST_CASE(pass_dynamic_arguments_to_the_base_base)
}
uint public m_i;
}
- contract Base1 is Base(3) {
+ contract Base1 is Base {
function Base1(uint k) Base(k*k) {}
}
- contract Derived is Base(3), Base1(2) {
+ contract Derived is Base, Base1 {
function Derived(uint i) Base(i) Base1(i)
{}
}
@@ -5170,7 +5235,7 @@ BOOST_AUTO_TEST_CASE(pass_dynamic_arguments_to_the_base_base_with_gap)
uint public m_i;
}
contract Base1 is Base(3) {}
- contract Derived is Base(2), Base1 {
+ contract Derived is Base, Base1 {
function Derived(uint i) Base(i) {}
}
contract Final is Derived(4) {
@@ -7687,7 +7752,6 @@ BOOST_AUTO_TEST_CASE(create_memory_array_allocation_size)
ABI_CHECK(callContractFunction("f()"), encodeArgs(0x40, 0x40, 0x20 + 256));
}
-
BOOST_AUTO_TEST_CASE(memory_arrays_of_various_sizes)
{
// Computes binomial coefficients the chinese way
@@ -7710,6 +7774,41 @@ BOOST_AUTO_TEST_CASE(memory_arrays_of_various_sizes)
ABI_CHECK(callContractFunction("f(uint256,uint256)", encodeArgs(u256(9), u256(5))), encodeArgs(u256(70)));
}
+BOOST_AUTO_TEST_CASE(create_multiple_dynamic_arrays)
+{
+ char const* sourceCode = R"(
+ contract C {
+ function f() returns (uint) {
+ uint[][] memory x = new uint[][](42);
+ assert(x[0].length == 0);
+ x[0] = new uint[](1);
+ x[0][0] = 1;
+ assert(x[4].length == 0);
+ x[4] = new uint[](1);
+ x[4][0] = 2;
+ assert(x[10].length == 0);
+ x[10] = new uint[](1);
+ x[10][0] = 44;
+ uint[][] memory y = new uint[][](24);
+ assert(y[0].length == 0);
+ y[0] = new uint[](1);
+ y[0][0] = 1;
+ assert(y[4].length == 0);
+ y[4] = new uint[](1);
+ y[4][0] = 2;
+ assert(y[10].length == 0);
+ y[10] = new uint[](1);
+ y[10][0] = 88;
+ if ((x[0][0] == y[0][0]) && (x[4][0] == y[4][0]) && (x[10][0] == 44) && (y[10][0] == 88))
+ return 7;
+ return 0;
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+ ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(7)));
+}
+
BOOST_AUTO_TEST_CASE(memory_overwrite)
{
char const* sourceCode = R"(
@@ -10998,6 +11097,179 @@ BOOST_AUTO_TEST_CASE(staticcall_for_view_and_pure)
}
}
+BOOST_AUTO_TEST_CASE(swap_peephole_optimisation)
+{
+ char const* sourceCode = R"(
+ contract C {
+ function lt(uint a, uint b) returns (bool c) {
+ assembly {
+ a
+ b
+ swap1
+ lt
+ =: c
+ }
+ }
+ function add(uint a, uint b) returns (uint c) {
+ assembly {
+ a
+ b
+ swap1
+ add
+ =: c
+ }
+ }
+ function div(uint a, uint b) returns (uint c) {
+ assembly {
+ a
+ b
+ swap1
+ div
+ =: c
+ }
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("lt(uint256,uint256)", u256(1), u256(2)) == encodeArgs(u256(1)));
+ BOOST_CHECK(callContractFunction("lt(uint256,uint256)", u256(2), u256(1)) == encodeArgs(u256(0)));
+ BOOST_CHECK(callContractFunction("add(uint256,uint256)", u256(1), u256(2)) == encodeArgs(u256(3)));
+ BOOST_CHECK(callContractFunction("add(uint256,uint256)", u256(100), u256(200)) == encodeArgs(u256(300)));
+ BOOST_CHECK(callContractFunction("div(uint256,uint256)", u256(2), u256(1)) == encodeArgs(u256(2)));
+ BOOST_CHECK(callContractFunction("div(uint256,uint256)", u256(200), u256(10)) == encodeArgs(u256(20)));
+ BOOST_CHECK(callContractFunction("div(uint256,uint256)", u256(1), u256(0)) == encodeArgs(u256(0)));
+ BOOST_CHECK(callContractFunction("div(uint256,uint256)", u256(0), u256(1)) == encodeArgs(u256(0)));
+}
+
+BOOST_AUTO_TEST_CASE(bitwise_shifting_constantinople)
+{
+ if (!dev::test::Options::get().evmVersion().hasBitwiseShifting())
+ return;
+ char const* sourceCode = R"(
+ contract C {
+ function shl(uint a, uint b) returns (uint c) {
+ assembly {
+ a
+ b
+ shl
+ =: c
+ }
+ }
+ function shr(uint a, uint b) returns (uint c) {
+ assembly {
+ a
+ b
+ shr
+ =: c
+ }
+ }
+ function sar(uint a, uint b) returns (uint c) {
+ assembly {
+ a
+ b
+ sar
+ =: c
+ }
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("shl(uint256,uint256)", u256(1), u256(2)) == encodeArgs(u256(4)));
+ BOOST_CHECK(callContractFunction("shl(uint256,uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), u256(1)) == encodeArgs(u256("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe")));
+ BOOST_CHECK(callContractFunction("shl(uint256,uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), u256(256)) == encodeArgs(u256(0)));
+ BOOST_CHECK(callContractFunction("shr(uint256,uint256)", u256(3), u256(1)) == encodeArgs(u256(1)));
+ BOOST_CHECK(callContractFunction("shr(uint256,uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), u256(1)) == encodeArgs(u256("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")));
+ BOOST_CHECK(callContractFunction("shr(uint256,uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), u256(255)) == encodeArgs(u256(1)));
+ BOOST_CHECK(callContractFunction("shr(uint256,uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), u256(256)) == encodeArgs(u256(0)));
+ BOOST_CHECK(callContractFunction("sar(uint256,uint256)", u256(3), u256(1)) == encodeArgs(u256(1)));
+ BOOST_CHECK(callContractFunction("sar(uint256,uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), u256(1)) == encodeArgs(u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")));
+ BOOST_CHECK(callContractFunction("sar(uint256,uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), u256(255)) == encodeArgs(u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")));
+ BOOST_CHECK(callContractFunction("sar(uint256,uint256)", u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), u256(256)) == encodeArgs(u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")));
+}
+
+BOOST_AUTO_TEST_CASE(bitwise_shifting_constants_constantinople)
+{
+ if (!dev::test::Options::get().evmVersion().hasBitwiseShifting())
+ return;
+ char const* sourceCode = R"(
+ contract C {
+ function shl_1() returns (bool) {
+ uint c;
+ assembly {
+ 1
+ 2
+ shl
+ =: c
+ }
+ assert(c == 4);
+ return true;
+ }
+ function shl_2() returns (bool) {
+ uint c;
+ assembly {
+ 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
+ 1
+ shl
+ =: c
+ }
+ assert(c == 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe);
+ return true;
+ }
+ function shl_3() returns (bool) {
+ uint c;
+ assembly {
+ 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
+ 256
+ shl
+ =: c
+ }
+ assert(c == 0);
+ return true;
+ }
+ function shr_1() returns (bool) {
+ uint c;
+ assembly {
+ 3
+ 1
+ shr
+ =: c
+ }
+ assert(c == 1);
+ return true;
+ }
+ function shr_2() returns (bool) {
+ uint c;
+ assembly {
+ 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
+ 1
+ shr
+ =: c
+ }
+ assert(c == 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
+ return true;
+ }
+ function shr_3() returns (bool) {
+ uint c;
+ assembly {
+ 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
+ 256
+ shr
+ =: c
+ }
+ assert(c == 0);
+ return true;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("shl_1()") == encodeArgs(u256(1)));
+ BOOST_CHECK(callContractFunction("shl_2()") == encodeArgs(u256(1)));
+ BOOST_CHECK(callContractFunction("shl_3()") == encodeArgs(u256(1)));
+ BOOST_CHECK(callContractFunction("shr_1()") == encodeArgs(u256(1)));
+ BOOST_CHECK(callContractFunction("shr_2()") == encodeArgs(u256(1)));
+ BOOST_CHECK(callContractFunction("shr_3()") == encodeArgs(u256(1)));
+}
+
BOOST_AUTO_TEST_SUITE_END()
}
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index dcdc1519..18a414e0 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -92,61 +92,6 @@ BOOST_AUTO_TEST_CASE(reference_to_later_declaration)
CHECK_SUCCESS(text);
}
-BOOST_AUTO_TEST_CASE(struct_definition_directly_recursive)
-{
- char const* text = R"(
- contract test {
- struct MyStructName {
- address addr;
- MyStructName x;
- }
- }
- )";
- CHECK_ERROR(text, TypeError, "Recursive struct definition.");
-}
-
-BOOST_AUTO_TEST_CASE(struct_definition_indirectly_recursive)
-{
- char const* text = R"(
- contract test {
- struct MyStructName1 {
- address addr;
- uint256 count;
- MyStructName2 x;
- }
- struct MyStructName2 {
- MyStructName1 x;
- }
- }
- )";
- CHECK_ERROR(text, TypeError, "Recursive struct definition.");
-}
-
-BOOST_AUTO_TEST_CASE(struct_definition_not_really_recursive)
-{
- char const* text = R"(
- contract test {
- struct s1 { uint a; }
- struct s2 { s1 x; s1 y; }
- }
- )";
- CHECK_SUCCESS(text);
-}
-
-BOOST_AUTO_TEST_CASE(struct_definition_recursion_via_mapping)
-{
- char const* text = R"(
- contract test {
- struct MyStructName1 {
- address addr;
- uint256 count;
- mapping(uint => MyStructName1) x;
- }
- }
- )";
- CHECK_SUCCESS(text);
-}
-
BOOST_AUTO_TEST_CASE(type_inference_smoke_test)
{
char const* text = R"(
@@ -962,6 +907,35 @@ BOOST_AUTO_TEST_CASE(base_constructor_arguments_override)
CHECK_SUCCESS(text);
}
+BOOST_AUTO_TEST_CASE(new_constructor_syntax)
+{
+ char const* text = R"(
+ contract A { constructor() public {} }
+ )";
+ CHECK_SUCCESS_NO_WARNINGS(text);
+}
+
+BOOST_AUTO_TEST_CASE(old_constructor_syntax)
+{
+ char const* text = R"(
+ contract A { function A() public {} }
+ )";
+ CHECK_WARNING(
+ text,
+ "Defining constructors as functions with the same name as the contract is deprecated."
+ );
+
+ text = R"(
+ pragma experimental "v0.5.0";
+ contract A { function A() public {} }
+ )";
+ CHECK_ERROR(
+ text,
+ SyntaxError,
+ "Functions are not allowed to have the same name as the contract."
+ );
+}
+
BOOST_AUTO_TEST_CASE(implicit_derived_to_base_conversion)
{
char const* text = R"(
@@ -1001,139 +975,6 @@ BOOST_AUTO_TEST_CASE(super_excludes_current_contract)
CHECK_ERROR(text, TypeError, "Member \"f\" not found or not visible after argument-dependent lookup in contract super B");
}
-BOOST_AUTO_TEST_CASE(function_modifier_invocation)
-{
- char const* text = R"(
- contract B {
- function f() mod1(2, true) mod2("0123456") pure public { }
- modifier mod1(uint a, bool b) { if (b) _; }
- modifier mod2(bytes7 a) { while (a == "1234567") _; }
- }
- )";
- CHECK_SUCCESS(text);
-}
-
-BOOST_AUTO_TEST_CASE(invalid_function_modifier_type)
-{
- char const* text = R"(
- contract B {
- function f() mod1(true) public { }
- modifier mod1(uint a) { if (a > 0) _; }
- }
- )";
- CHECK_ERROR(text, TypeError, "Invalid type for argument in modifier invocation. Invalid implicit conversion from bool to uint256 requested.");
-}
-
-BOOST_AUTO_TEST_CASE(function_modifier_invocation_parameters)
-{
- char const* text = R"(
- contract B {
- function f(uint8 a) mod1(a, true) mod2(r) public returns (bytes7 r) { }
- modifier mod1(uint a, bool b) { if (b) _; }
- modifier mod2(bytes7 a) { while (a == "1234567") _; }
- }
- )";
- CHECK_SUCCESS(text);
-}
-
-BOOST_AUTO_TEST_CASE(function_modifier_invocation_local_variables)
-{
- char const* text = R"(
- contract B {
- function f() mod(x) pure public { uint x = 7; }
- modifier mod(uint a) { if (a > 0) _; }
- }
- )";
- CHECK_SUCCESS_NO_WARNINGS(text);
-}
-
-BOOST_AUTO_TEST_CASE(function_modifier_invocation_local_variables050)
-{
- char const* text = R"(
- pragma experimental "v0.5.0";
- contract B {
- function f() mod(x) pure public { uint x = 7; }
- modifier mod(uint a) { if (a > 0) _; }
- }
- )";
- CHECK_ERROR(text, DeclarationError, "Undeclared identifier.");
-}
-
-BOOST_AUTO_TEST_CASE(function_modifier_double_invocation)
-{
- char const* text = R"(
- contract B {
- function f(uint x) mod(x) mod(2) public { }
- modifier mod(uint a) { if (a > 0) _; }
- }
- )";
- CHECK_SUCCESS(text);
-}
-
-BOOST_AUTO_TEST_CASE(base_constructor_double_invocation)
-{
- char const* text = R"(
- contract C { function C(uint a) public {} }
- contract B is C {
- function B() C(2) C(2) public {}
- }
- )";
- CHECK_ERROR(text, DeclarationError, "Base constructor already provided");
-}
-
-BOOST_AUTO_TEST_CASE(legal_modifier_override)
-{
- char const* text = R"(
- contract A { modifier mod(uint a) { _; } }
- contract B is A { modifier mod(uint a) { _; } }
- )";
- CHECK_SUCCESS(text);
-}
-
-BOOST_AUTO_TEST_CASE(illegal_modifier_override)
-{
- char const* text = R"(
- contract A { modifier mod(uint a) { _; } }
- contract B is A { modifier mod(uint8 a) { _; } }
- )";
- CHECK_ERROR(text, TypeError, "Override changes modifier signature.");
-}
-
-BOOST_AUTO_TEST_CASE(modifier_overrides_function)
-{
- char const* text = R"(
- contract A { modifier mod(uint a) { _; } }
- contract B is A { function mod(uint a) public { } }
- )";
- CHECK_ALLOW_MULTI(text, (vector<pair<Error::Type, string>>{
- {Error::Type::DeclarationError, "Identifier already declared"},
- {Error::Type::TypeError, "Override changes modifier to function"}
- }));
-}
-
-BOOST_AUTO_TEST_CASE(function_overrides_modifier)
-{
- char const* text = R"(
- contract A { function mod(uint a) public { } }
- contract B is A { modifier mod(uint a) { _; } }
- )";
- CHECK_ALLOW_MULTI(text, (vector<pair<Error::Type, string>>{
- {Error::Type::DeclarationError, "Identifier already declared"},
- {Error::Type::TypeError, "Override changes function to modifier"}
- }));
-}
-
-BOOST_AUTO_TEST_CASE(modifier_returns_value)
-{
- char const* text = R"(
- contract A {
- function f(uint a) mod(2) public returns (uint r) { }
- modifier mod(uint a) { _; return 7; }
- }
- )";
- CHECK_ERROR(text, TypeError, "Return arguments not allowed.");
-}
-
BOOST_AUTO_TEST_CASE(state_variable_accessors)
{
char const* text = R"(
@@ -4202,21 +4043,6 @@ BOOST_AUTO_TEST_CASE(conditional_with_all_types)
CHECK_SUCCESS(text);
}
-BOOST_AUTO_TEST_CASE(constructor_call_invalid_arg_count)
-{
- // This caused a segfault in an earlier version
- char const* text = R"(
- contract C {
- function C(){}
- }
- contract D is C {
- function D() C(5){}
- }
- )";
-
- CHECK_ERROR(text, TypeError, "Wrong argument count for modifier invocation: 1 arguments given but expected 0.");
-}
-
BOOST_AUTO_TEST_CASE(index_access_for_bytes)
{
char const* text = R"(
@@ -5081,16 +4907,6 @@ BOOST_AUTO_TEST_CASE(no_warn_about_callcode_as_function)
CHECK_SUCCESS_NO_WARNINGS(text);
}
-BOOST_AUTO_TEST_CASE(modifier_without_underscore)
-{
- char const* text = R"(
- contract test {
- modifier m() {}
- }
- )";
- CHECK_ERROR(text, SyntaxError, "Modifier body does not contain '_'.");
-}
-
BOOST_AUTO_TEST_CASE(payable_in_library)
{
char const* text = R"(
@@ -5290,319 +5106,6 @@ BOOST_AUTO_TEST_CASE(using_directive_for_missing_selftype)
CHECK_ERROR(text, TypeError, "Member \"b\" not found or not visible after argument-dependent lookup in bytes memory");
}
-BOOST_AUTO_TEST_CASE(function_type)
-{
- char const* text = R"(
- contract C {
- function f() public {
- function(uint) returns (uint) x;
- }
- }
- )";
- CHECK_SUCCESS(text);
-}
-
-BOOST_AUTO_TEST_CASE(function_type_parameter)
-{
- char const* text = R"(
- contract C {
- function f(function(uint) external returns (uint) g) public returns (function(uint) external returns (uint)) {
- return g;
- }
- }
- )";
- CHECK_SUCCESS(text);
-}
-
-BOOST_AUTO_TEST_CASE(function_type_returned)
-{
- char const* text = R"(
- contract C {
- function f() public returns (function(uint) external returns (uint) g) {
- return g;
- }
- }
- )";
- CHECK_SUCCESS(text);
-}
-
-BOOST_AUTO_TEST_CASE(private_function_type)
-{
- char const* text = R"(
- contract C {
- function f() public {
- function(uint) private returns (uint) x;
- }
- }
- )";
- CHECK_ERROR(text, TypeError, "Invalid visibility, can only be \"external\" or \"internal\".");
-}
-
-BOOST_AUTO_TEST_CASE(public_function_type)
-{
- char const* text = R"(
- contract C {
- function f() public {
- function(uint) public returns (uint) x;
- }
- }
- )";
- CHECK_ERROR(text, TypeError, "Invalid visibility, can only be \"external\" or \"internal\".");
-}
-
-BOOST_AUTO_TEST_CASE(payable_internal_function_type)
-{
- char const* text = R"(
- contract C {
- function (uint) internal payable returns (uint) x;
- }
- )";
- CHECK_ERROR(text, TypeError, "Only external function types can be payable.");
-}
-
-BOOST_AUTO_TEST_CASE(payable_internal_function_type_is_not_fatal)
-{
- char const* text = R"(
- contract C {
- function (uint) internal payable returns (uint) x;
-
- function g() {
- x = g;
- }
- }
- )";
- CHECK_ERROR_ALLOW_MULTI(text, TypeError, (std::vector<std::string>{"Only external function types can be payable."}));
-}
-
-BOOST_AUTO_TEST_CASE(call_value_on_non_payable_function_type)
-{
- char const* text = R"(
- contract C {
- function (uint) external returns (uint) x;
- function f() public {
- x.value(2)();
- }
- }
- )";
- CHECK_ERROR(text, TypeError, "Member \"value\" not found or not visible after argument-dependent lookup in function (uint256) external returns (uint256) - did you forget the \"payable\" modifier?");
-}
-
-BOOST_AUTO_TEST_CASE(external_function_type_returning_internal)
-{
- char const* text = R"(
- contract C {
- function() external returns (function () internal) x;
- }
- )";
- CHECK_ERROR(text, TypeError, "Internal type cannot be used for external function type.");
-}
-
-BOOST_AUTO_TEST_CASE(external_function_type_taking_internal)
-{
- char const* text = R"(
- contract C {
- function(function () internal) external x;
- }
- )";
- CHECK_ERROR(text, TypeError, "Internal type cannot be used for external function type.");
-}
-
-BOOST_AUTO_TEST_CASE(call_value_on_payable_function_type)
-{
- char const* text = R"(
- contract C {
- function (uint) external payable returns (uint) x;
- function f() public {
- x.value(2)(1);
- }
- }
- )";
- CHECK_SUCCESS(text);
-}
-
-BOOST_AUTO_TEST_CASE(internal_function_as_external_parameter)
-{
- // It should not be possible to give internal functions
- // as parameters to external functions.
- char const* text = R"(
- contract C {
- function f(function(uint) internal returns (uint) x) public {
- }
- }
- )";
- CHECK_ERROR(text, TypeError, "Internal or recursive type is not allowed for public or external functions.");
-}
-
-BOOST_AUTO_TEST_CASE(internal_function_returned_from_public_function)
-{
- // It should not be possible to return internal functions from external functions.
- char const* text = R"(
- contract C {
- function f() public returns (function(uint) internal returns (uint) x) {
- }
- }
- )";
- CHECK_ERROR(text, TypeError, "Internal or recursive type is not allowed for public or external functions.");
-}
-
-BOOST_AUTO_TEST_CASE(internal_function_as_external_parameter_in_library_internal)
-{
- char const* text = R"(
- library L {
- function f(function(uint) internal returns (uint) x) internal {
- }
- }
- )";
- CHECK_SUCCESS(text);
-}
-
-BOOST_AUTO_TEST_CASE(internal_function_as_external_parameter_in_library_external)
-{
- char const* text = R"(
- library L {
- function f(function(uint) internal returns (uint) x) public {
- }
- }
- )";
- CHECK_ERROR(text, TypeError, "Internal or recursive type is not allowed for public or external functions.");
-}
-
-BOOST_AUTO_TEST_CASE(function_type_arrays)
-{
- char const* text = R"(
- contract C {
- function(uint) external returns (uint)[] public x;
- function(uint) internal returns (uint)[10] y;
- function f() public {
- function(uint) returns (uint)[10] memory a;
- function(uint) returns (uint)[10] storage b = y;
- function(uint) external returns (uint)[] memory c;
- c = new function(uint) external returns (uint)[](200);
- a; b;
- }
- }
- )";
- CHECK_SUCCESS(text);
-}
-
-BOOST_AUTO_TEST_CASE(delete_function_type)
-{
- char const* text = R"(
- contract C {
- function(uint) external returns (uint) x;
- function(uint) internal returns (uint) y;
- function f() public {
- delete x;
- var a = y;
- delete a;
- delete y;
- var c = f;
- delete c;
- function(uint) internal returns (uint) g;
- delete g;
- }
- }
- )";
- CHECK_SUCCESS(text);
-}
-
-BOOST_AUTO_TEST_CASE(delete_function_type_invalid)
-{
- char const* text = R"(
- contract C {
- function f() public {
- delete f;
- }
- }
- )";
- CHECK_ERROR(text, TypeError, "Expression has to be an lvalue.");
-}
-
-BOOST_AUTO_TEST_CASE(delete_external_function_type_invalid)
-{
- char const* text = R"(
- contract C {
- function f() public {
- delete this.f;
- }
- }
- )";
- CHECK_ERROR(text, TypeError, "Expression has to be an lvalue.");
-}
-
-BOOST_AUTO_TEST_CASE(external_function_to_function_type_calldata_parameter)
-{
- // This is a test that checks that the type of the `bytes` parameter is
- // correctly changed from its own type `bytes calldata` to `bytes memory`
- // when converting to a function type.
- char const* text = R"(
- contract C {
- function f(function(bytes memory) external g) public { }
- function callback(bytes) external {}
- function g() public {
- f(this.callback);
- }
- }
- )";
- CHECK_SUCCESS(text);
-}
-
-BOOST_AUTO_TEST_CASE(external_function_type_to_address)
-{
- char const* text = R"(
- contract C {
- function f() public returns (address) {
- return address(this.f);
- }
- }
- )";
- CHECK_SUCCESS(text);
-}
-
-BOOST_AUTO_TEST_CASE(internal_function_type_to_address)
-{
- char const* text = R"(
- contract C {
- function f() public returns (address) {
- return address(f);
- }
- }
- )";
- CHECK_ERROR(text, TypeError, "Explicit type conversion not allowed");
-}
-
-BOOST_AUTO_TEST_CASE(external_function_type_to_uint)
-{
- char const* text = R"(
- contract C {
- function f() public returns (uint) {
- return uint(this.f);
- }
- }
- )";
- CHECK_ERROR(text, TypeError, "Explicit type conversion not allowed");
-}
-
-BOOST_AUTO_TEST_CASE(warn_function_type_parameters_with_names)
-{
- char const* text = R"(
- contract C {
- function(uint a) f;
- }
- )";
- CHECK_WARNING(text, "Naming function type parameters is deprecated.");
-}
-
-BOOST_AUTO_TEST_CASE(warn_function_type_return_parameters_with_names)
-{
- char const* text = R"(
- contract C {
- function(uint) returns (bool ret) f;
- }
- )";
- CHECK_WARNING(text, "Naming function type return parameters is deprecated.");
-}
-
BOOST_AUTO_TEST_CASE(shift_constant_left_negative_rvalue)
{
char const* text = R"(
@@ -6193,44 +5696,6 @@ BOOST_AUTO_TEST_CASE(read_returned_struct)
)";
CHECK_WARNING(text, "Experimental features");
}
-
-BOOST_AUTO_TEST_CASE(return_recursive_structs)
-{
- char const* text = R"(
- contract C {
- struct S { uint a; S[] sub; }
- function f() returns (uint, S) {
- }
- }
- )";
- CHECK_ERROR(text, TypeError, "Internal or recursive type is not allowed for public or external functions.");
-}
-
-BOOST_AUTO_TEST_CASE(return_recursive_structs2)
-{
- char const* text = R"(
- contract C {
- struct S { uint a; S[2][] sub; }
- function f() returns (uint, S) {
- }
- }
- )";
- CHECK_ERROR(text, TypeError, "Internal or recursive type is not allowed for public or external functions.");
-}
-
-BOOST_AUTO_TEST_CASE(return_recursive_structs3)
-{
- char const* text = R"(
- contract C {
- struct S { uint a; S[][][] sub; }
- struct T { S s; }
- function f() returns (uint x, T t) {
- }
- }
- )";
- CHECK_ERROR(text, TypeError, "Internal or recursive type is not allowed for public or external functions.");
-}
-
BOOST_AUTO_TEST_CASE(address_checksum_type_deduction)
{
char const* text = R"(
@@ -6353,38 +5818,6 @@ BOOST_AUTO_TEST_CASE(address_methods)
CHECK_SUCCESS(text);
}
-BOOST_AUTO_TEST_CASE(cyclic_dependency_for_constants)
-{
- char const* text = R"(
- contract C {
- uint constant a = a;
- }
- )";
- CHECK_ERROR(text, TypeError, "cyclic dependency via a");
- text = R"(
- contract C {
- uint constant a = b * c;
- uint constant b = 7;
- uint constant c = b + uint(keccak256(d));
- uint constant d = 2 + a;
- }
- )";
- CHECK_ERROR_ALLOW_MULTI(text, TypeError, (std::vector<std::string>{
- "a has a cyclic dependency via c",
- "c has a cyclic dependency via d",
- "d has a cyclic dependency via a"
- }));
- text = R"(
- contract C {
- uint constant a = b * c;
- uint constant b = 7;
- uint constant c = 4 + uint(keccak256(d));
- uint constant d = 2 + b;
- }
- )";
- CHECK_SUCCESS(text);
-}
-
BOOST_AUTO_TEST_CASE(interface)
{
char const* text = R"(
@@ -6916,7 +6349,7 @@ BOOST_AUTO_TEST_CASE(shadowing_builtins_ignores_constructor)
{
char const* text = R"(
contract C {
- function C() public {}
+ constructor() public {}
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
@@ -7328,7 +6761,7 @@ BOOST_AUTO_TEST_CASE(using_this_in_constructor)
{
char const* text = R"(
contract C {
- function C() public {
+ constructor() public {
this.f();
}
function f() pure public {
@@ -7816,171 +7249,6 @@ BOOST_AUTO_TEST_CASE(address_overload_resolution)
CHECK_SUCCESS(text);
}
-BOOST_AUTO_TEST_CASE(array_length_too_large)
-{
- char const* text = R"(
- contract C {
- uint[8**90] ids;
- }
- )";
- CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression.");
-}
-
-BOOST_AUTO_TEST_CASE(array_length_not_convertible_to_integer)
-{
- char const* text = R"(
- contract C {
- uint[true] ids;
- }
- )";
- CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression.");
-}
-
-BOOST_AUTO_TEST_CASE(array_length_constant_var)
-{
- char const* text = R"(
- contract C {
- uint constant LEN = 10;
- uint[LEN] ids;
- }
- )";
- CHECK_SUCCESS(text);
-}
-
-BOOST_AUTO_TEST_CASE(array_length_non_integer_constant_var)
-{
- char const* text = R"(
- contract C {
- bool constant LEN = true;
- uint[LEN] ids;
- }
- )";
- CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression.");
-}
-
-BOOST_AUTO_TEST_CASE(array_length_cannot_be_function)
-{
- char const* text = R"(
- contract C {
- function f() {}
- uint[f] ids;
- }
- )";
- CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression.");
-}
-
-BOOST_AUTO_TEST_CASE(array_length_can_be_recursive_constant)
-{
- char const* text = R"(
- contract C {
- uint constant L = 5;
- uint constant LEN = L + 4 * L;
- uint[LEN] ids;
- }
- )";
- CHECK_SUCCESS(text);
-}
-
-BOOST_AUTO_TEST_CASE(array_length_cannot_be_function_call)
-{
- char const* text = R"(
- contract C {
- function f(uint x) {}
- uint constant LEN = f();
- uint[LEN] ids;
- }
- )";
- CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression.");
-}
-
-BOOST_AUTO_TEST_CASE(array_length_const_cannot_be_fractional)
-{
- char const* text = R"(
- contract C {
- fixed constant L = 10.5;
- uint[L] ids;
- }
- )";
- CHECK_ERROR(text, TypeError, "Array with fractional length specified");
-}
-
-BOOST_AUTO_TEST_CASE(array_length_can_be_constant_in_struct)
-{
- char const* text = R"(
- contract C {
- uint constant LEN = 10;
- struct Test {
- uint[LEN] ids;
- }
- }
- )";
- CHECK_SUCCESS(text);
-}
-
-BOOST_AUTO_TEST_CASE(array_length_can_be_constant_in_function)
-{
- char const* text = R"(
- contract C {
- uint constant LEN = 10;
- function f() {
- uint[LEN] a;
- }
- }
- )";
- CHECK_SUCCESS(text);
-}
-
-BOOST_AUTO_TEST_CASE(array_length_cannot_be_constant_function_parameter)
-{
- char const* text = R"(
- contract C {
- function f(uint constant LEN) {
- uint[LEN] a;
- }
- }
- )";
- CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression.");
-}
-
-BOOST_AUTO_TEST_CASE(array_length_with_cyclic_constant)
-{
- char const* text = R"(
- contract C {
- uint constant LEN = LEN;
- function f() {
- uint[LEN] a;
- }
- }
- )";
- CHECK_ERROR(text, TypeError, "Cyclic constant definition (or maximum recursion depth exhausted).");
-}
-
-BOOST_AUTO_TEST_CASE(array_length_with_complex_cyclic_constant)
-{
- char const* text = R"(
- contract C {
- uint constant L2 = LEN - 10;
- uint constant L1 = L2 / 10;
- uint constant LEN = 10 + L1 * 5;
- function f() {
- uint[LEN] a;
- }
- }
- )";
- CHECK_ERROR(text, TypeError, "Cyclic constant definition (or maximum recursion depth exhausted).");
-}
-
-BOOST_AUTO_TEST_CASE(array_length_with_pure_functions)
-{
- char const* text = R"(
- contract C {
- uint constant LEN = keccak256(ripemd160(33));
- uint[LEN] ids;
- }
- )";
- CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression.");
-}
-
BOOST_AUTO_TEST_CASE(array_length_invalid_expression)
{
char const* text = R"(
diff --git a/test/libsolidity/SolidityOptimizer.cpp b/test/libsolidity/SolidityOptimizer.cpp
index cf4550c7..5326feaf 100644
--- a/test/libsolidity/SolidityOptimizer.cpp
+++ b/test/libsolidity/SolidityOptimizer.cpp
@@ -93,8 +93,10 @@ public:
{
m_contractAddress = m_nonOptimizedContract;
bytes nonOptimizedOutput = callContractFunction(_sig, _arguments...);
+ m_gasUsedNonOptimized = m_gasUsed;
m_contractAddress = m_optimizedContract;
bytes optimizedOutput = callContractFunction(_sig, _arguments...);
+ m_gasUsedOptimized = m_gasUsed;
BOOST_CHECK_MESSAGE(!optimizedOutput.empty(), "No optimized output for " + _sig);
BOOST_CHECK_MESSAGE(!nonOptimizedOutput.empty(), "No un-optimized output for " + _sig);
BOOST_CHECK_MESSAGE(nonOptimizedOutput == optimizedOutput, "Computed values do not match."
@@ -120,6 +122,8 @@ public:
}
protected:
+ u256 m_gasUsedOptimized;
+ u256 m_gasUsedNonOptimized;
bytes m_nonOptimizedBytecode;
bytes m_optimizedBytecode;
Address m_optimizedContract;
@@ -584,6 +588,26 @@ BOOST_AUTO_TEST_CASE(invalid_state_at_control_flow_join)
compareVersions("test()");
}
+BOOST_AUTO_TEST_CASE(init_empty_dynamic_arrays)
+{
+ // This is not so much an optimizer test, but rather a test
+ // that allocating empty arrays is implemented efficiently.
+ // In particular, initializing a dynamic memory array does
+ // not use any memory.
+ char const* sourceCode = R"(
+ contract Test {
+ function f() pure returns (uint r) {
+ uint[][] memory x = new uint[][](20000);
+ return x.length;
+ }
+ }
+ )";
+ compileBothVersions(sourceCode);
+ compareVersions("f()");
+ BOOST_CHECK_LE(m_gasUsedNonOptimized, 1900000);
+ BOOST_CHECK_LE(1600000, m_gasUsedNonOptimized);
+}
+
BOOST_AUTO_TEST_CASE(optimise_multi_stores)
{
char const* sourceCode = R"(
@@ -603,8 +627,8 @@ BOOST_AUTO_TEST_CASE(optimise_multi_stores)
)";
compileBothVersions(sourceCode);
compareVersions("f()");
- BOOST_CHECK_EQUAL(numInstructions(m_nonOptimizedBytecode, Instruction::SSTORE), 13);
- BOOST_CHECK_EQUAL(numInstructions(m_optimizedBytecode, Instruction::SSTORE), 11);
+ BOOST_CHECK_EQUAL(numInstructions(m_nonOptimizedBytecode, Instruction::SSTORE), 9);
+ BOOST_CHECK_EQUAL(numInstructions(m_optimizedBytecode, Instruction::SSTORE), 8);
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp
index 4e862f60..93e6bcaa 100644
--- a/test/libsolidity/SolidityParser.cpp
+++ b/test/libsolidity/SolidityParser.cpp
@@ -112,26 +112,6 @@ while(0)
BOOST_AUTO_TEST_SUITE(SolidityParser)
-BOOST_AUTO_TEST_CASE(smoke_test)
-{
- char const* text = R"(
- contract test {
- uint256 stateVariable1;
- }
- )";
- BOOST_CHECK(successParse(text));
-}
-
-BOOST_AUTO_TEST_CASE(missing_variable_name_in_declaration)
-{
- char const* text = R"(
- contract test {
- uint256 ;
- }
- )";
- CHECK_PARSE_ERROR(text, "Expected identifier");
-}
-
BOOST_AUTO_TEST_CASE(empty_function)
{
char const* text = R"(
diff --git a/test/libsolidity/SolidityTypes.cpp b/test/libsolidity/SolidityTypes.cpp
index bc9f2fe1..738b24bc 100644
--- a/test/libsolidity/SolidityTypes.cpp
+++ b/test/libsolidity/SolidityTypes.cpp
@@ -123,6 +123,7 @@ BOOST_AUTO_TEST_CASE(type_identifiers)
BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("bytes32")->identifier(), "t_bytes32");
BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("bool")->identifier(), "t_bool");
BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("bytes")->identifier(), "t_bytes_storage_ptr");
+ BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("bytes memory")->identifier(), "t_bytes_memory_ptr");
BOOST_CHECK_EQUAL(Type::fromElementaryTypeName("string")->identifier(), "t_string_storage_ptr");
ArrayType largeintArray(DataLocation::Memory, Type::fromElementaryTypeName("int128"), u256("2535301200456458802993406410752"));
BOOST_CHECK_EQUAL(largeintArray.identifier(), "t_array$_t_int128_$2535301200456458802993406410752_memory_ptr");
diff --git a/test/libsolidity/StandardCompiler.cpp b/test/libsolidity/StandardCompiler.cpp
index dd6eb7c4..b285a2a0 100644
--- a/test/libsolidity/StandardCompiler.cpp
+++ b/test/libsolidity/StandardCompiler.cpp
@@ -261,14 +261,14 @@ BOOST_AUTO_TEST_CASE(basic_compilation)
BOOST_CHECK(contract["evm"]["bytecode"]["object"].isString());
BOOST_CHECK_EQUAL(
dev::test::bytecodeSansMetadata(contract["evm"]["bytecode"]["object"].asString()),
- "60606040523415600e57600080fd5b603580601b6000396000f3006060604052600080fd00"
+ "60806040523415600e57600080fd5b603580601b6000396000f3006080604052600080fd00"
);
BOOST_CHECK(contract["evm"]["assembly"].isString());
BOOST_CHECK(contract["evm"]["assembly"].asString().find(
- " /* \"fileA\":0:14 contract A { } */\n mstore(0x40, 0x60)\n jumpi(tag_1, iszero(callvalue))\n"
+ " /* \"fileA\":0:14 contract A { } */\n mstore(0x40, 0x80)\n jumpi(tag_1, iszero(callvalue))\n"
" 0x0\n dup1\n revert\ntag_1:\n dataSize(sub_0)\n dup1\n dataOffset(sub_0)\n 0x0\n codecopy\n 0x0\n"
" return\nstop\n\nsub_0: assembly {\n /* \"fileA\":0:14 contract A { } */\n"
- " mstore(0x40, 0x60)\n 0x0\n dup1\n revert\n\n"
+ " mstore(0x40, 0x80)\n 0x0\n dup1\n revert\n\n"
" auxdata: 0xa165627a7a7230582") == 0);
BOOST_CHECK(contract["evm"]["gasEstimates"].isObject());
BOOST_CHECK_EQUAL(
diff --git a/test/libsolidity/SyntaxTest.cpp b/test/libsolidity/SyntaxTest.cpp
index ca051138..1c2355d5 100644
--- a/test/libsolidity/SyntaxTest.cpp
+++ b/test/libsolidity/SyntaxTest.cpp
@@ -16,6 +16,7 @@
*/
#include <test/libsolidity/SyntaxTest.h>
+#include <test/Options.h>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/throw_exception.hpp>
@@ -33,17 +34,38 @@ namespace fs = boost::filesystem;
using namespace boost::unit_test;
template<typename IteratorType>
-void skipWhitespace(IteratorType& it, IteratorType end)
+void skipWhitespace(IteratorType& _it, IteratorType _end)
{
- while (it != end && isspace(*it))
- ++it;
+ while (_it != _end && isspace(*_it))
+ ++_it;
}
template<typename IteratorType>
-void skipSlashes(IteratorType& it, IteratorType end)
+void skipSlashes(IteratorType& _it, IteratorType _end)
{
- while (it != end && *it == '/')
- ++it;
+ while (_it != _end && *_it == '/')
+ ++_it;
+}
+
+void expect(string::iterator& _it, string::iterator _end, string::value_type _c)
+{
+ if (_it == _end || *_it != _c)
+ throw runtime_error(string("Invalid test expectation. Expected: \"") + _c + "\".");
+ ++_it;
+}
+
+int parseUnsignedInteger(string::iterator &_it, string::iterator _end)
+{
+ if (_it == _end || !isdigit(*_it))
+ throw runtime_error("Invalid test expectation. Source location expected.");
+ int result = 0;
+ while (_it != _end && isdigit(*_it))
+ {
+ result *= 10;
+ result += *_it - '0';
+ ++_it;
+ }
+ return result;
}
SyntaxTest::SyntaxTest(string const& _filename)
@@ -59,93 +81,79 @@ SyntaxTest::SyntaxTest(string const& _filename)
bool SyntaxTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted)
{
- m_errorList = parseAnalyseAndReturnError(m_source, true, true, true).second;
- if (!matchesExpectations(m_errorList))
+ string const versionPragma = "pragma solidity >=0.0;\n";
+ m_compiler.reset();
+ m_compiler.addSource("", versionPragma + m_source);
+ m_compiler.setEVMVersion(dev::test::Options::get().evmVersion());
+
+ if (m_compiler.parse())
+ m_compiler.analyze();
+
+ for (auto const& currentError: filterErrors(m_compiler.errors(), true))
+ {
+ int locationStart = -1, locationEnd = -1;
+ if (auto location = boost::get_error_info<errinfo_sourceLocation>(*currentError))
+ {
+ // ignore the version pragma inserted by the testing tool when calculating locations.
+ if (location->start >= static_cast<int>(versionPragma.size()))
+ locationStart = location->start - versionPragma.size();
+ if (location->end >= static_cast<int>(versionPragma.size()))
+ locationEnd = location->end - versionPragma.size();
+ }
+ m_errorList.emplace_back(SyntaxTestError{
+ currentError->typeName(),
+ errorMessage(*currentError),
+ locationStart,
+ locationEnd
+ });
+ }
+
+ if (m_expectations != m_errorList)
{
- std::string nextIndentLevel = _linePrefix + " ";
+ string nextIndentLevel = _linePrefix + " ";
FormattedScope(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Expected result:" << endl;
- printExpected(_stream, nextIndentLevel, _formatted);
- FormattedScope(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Obtained result:\n";
- printErrorList(_stream, m_errorList, nextIndentLevel, false, false, _formatted);
+ printErrorList(_stream, m_expectations, nextIndentLevel, _formatted);
+ FormattedScope(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Obtained result:" << endl;
+ printErrorList(_stream, m_errorList, nextIndentLevel, _formatted);
return false;
}
return true;
}
-void SyntaxTest::printExpected(ostream& _stream, string const& _linePrefix, bool const _formatted) const
-{
- if (m_expectations.empty())
- FormattedScope(_stream, _formatted, {BOLD, GREEN}) << _linePrefix << "Success" << endl;
- else
- for (auto const& expectation: m_expectations)
- {
- FormattedScope(_stream, _formatted, {BOLD, expectation.type == "Warning" ? YELLOW : RED}) <<
- _linePrefix << expectation.type << ": ";
- _stream << expectation.message << endl;
- }
-}
-
void SyntaxTest::printErrorList(
ostream& _stream,
- ErrorList const& _errorList,
+ vector<SyntaxTestError> const& _errorList,
string const& _linePrefix,
- bool const _ignoreWarnings,
- bool const _lineNumbers,
bool const _formatted
-) const
+)
{
if (_errorList.empty())
FormattedScope(_stream, _formatted, {BOLD, GREEN}) << _linePrefix << "Success" << endl;
else
for (auto const& error: _errorList)
{
- bool isWarning = (error->type() == Error::Type::Warning);
- if (isWarning && _ignoreWarnings) continue;
-
{
- FormattedScope scope(_stream, _formatted, {BOLD, isWarning ? YELLOW : RED});
+ FormattedScope scope(_stream, _formatted, {BOLD, (error.type == "Warning") ? YELLOW : RED});
_stream << _linePrefix;
- if (_lineNumbers)
- {
- int line = offsetToLineNumber(
- boost::get_error_info<errinfo_sourceLocation>(*error)->start
- );
- if (line >= 0)
- _stream << "(" << line << "): ";
- }
- _stream << error->typeName() << ": ";
+ _stream << error.type << ": ";
+ }
+ if (error.locationStart >= 0 || error.locationEnd >= 0)
+ {
+ _stream << "(";
+ if (error.locationStart >= 0)
+ _stream << error.locationStart;
+ _stream << "-";
+ if (error.locationEnd >= 0)
+ _stream << error.locationEnd;
+ _stream << "): ";
}
- _stream << errorMessage(*error) << endl;
+ _stream << error.message << endl;
}
}
-int SyntaxTest::offsetToLineNumber(int _location) const
+string SyntaxTest::errorMessage(Exception const& _e)
{
- // parseAnalyseAndReturnError(...) prepends a version pragma
- _location -= strlen("pragma solidity >=0.0;\n");
- if (_location < 0 || static_cast<size_t>(_location) >= m_source.size())
- return -1;
- else
- return 1 + std::count(m_source.begin(), m_source.begin() + _location, '\n');
-}
-
-bool SyntaxTest::matchesExpectations(ErrorList const& _errorList) const
-{
- if (_errorList.size() != m_expectations.size())
- return false;
- else
- for (size_t i = 0; i < _errorList.size(); i++)
- if (
- (_errorList[i]->typeName() != m_expectations[i].type) ||
- (errorMessage(*_errorList[i]) != m_expectations[i].message)
- )
- return false;
- return true;
-}
-
-string SyntaxTest::errorMessage(Error const& _e)
-{
- if (_e.comment())
+ if (_e.comment() && !_e.comment()->empty())
return boost::replace_all_copy(*_e.comment(), "\n", "\\n");
else
return "NONE";
@@ -164,9 +172,9 @@ string SyntaxTest::parseSource(istream& _stream)
return source;
}
-vector<SyntaxTestExpectation> SyntaxTest::parseExpectations(istream& _stream)
+vector<SyntaxTestError> SyntaxTest::parseExpectations(istream& _stream)
{
- vector<SyntaxTestExpectation> expectations;
+ vector<SyntaxTestError> expectations;
string line;
while (getline(_stream, line))
{
@@ -187,8 +195,28 @@ vector<SyntaxTestExpectation> SyntaxTest::parseExpectations(istream& _stream)
skipWhitespace(it, line.end());
+ int locationStart = -1;
+ int locationEnd = -1;
+
+ if (it != line.end() && *it == '(')
+ {
+ ++it;
+ locationStart = parseUnsignedInteger(it, line.end());
+ expect(it, line.end(), '-');
+ locationEnd = parseUnsignedInteger(it, line.end());
+ expect(it, line.end(), ')');
+ expect(it, line.end(), ':');
+ }
+
+ skipWhitespace(it, line.end());
+
string errorMessage(it, line.end());
- expectations.emplace_back(SyntaxTestExpectation{move(errorType), move(errorMessage)});
+ expectations.emplace_back(SyntaxTestError{
+ move(errorType),
+ move(errorMessage),
+ locationStart,
+ locationEnd
+ });
}
return expectations;
}
@@ -239,9 +267,11 @@ int SyntaxTest::registerTests(
_suite.add(make_test_case(
[fullpath]
{
- std::stringstream errorStream;
- if (!SyntaxTest(fullpath.string()).run(errorStream))
- BOOST_ERROR("Test expectation mismatch.\n" + errorStream.str());
+ BOOST_REQUIRE_NO_THROW({
+ stringstream errorStream;
+ if (!SyntaxTest(fullpath.string()).run(errorStream))
+ BOOST_ERROR("Test expectation mismatch.\n" + errorStream.str());
+ });
},
_path.stem().string(),
*filenames.back(),
diff --git a/test/libsolidity/SyntaxTest.h b/test/libsolidity/SyntaxTest.h
index cb6ee05c..6159e789 100644
--- a/test/libsolidity/SyntaxTest.h
+++ b/test/libsolidity/SyntaxTest.h
@@ -36,10 +36,19 @@ namespace solidity
namespace test
{
-struct SyntaxTestExpectation
+struct SyntaxTestError
{
std::string type;
std::string message;
+ int locationStart;
+ int locationEnd;
+ bool operator==(SyntaxTestError const& _rhs) const
+ {
+ return type == _rhs.type &&
+ message == _rhs.message &&
+ locationStart == _rhs.locationStart &&
+ locationEnd == _rhs.locationEnd;
+ }
};
@@ -50,21 +59,16 @@ public:
bool run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false);
- std::vector<SyntaxTestExpectation> const& expectations() const { return m_expectations; }
+ std::vector<SyntaxTestError> const& expectations() const { return m_expectations; }
std::string const& source() const { return m_source; }
- ErrorList const& errorList() const { return m_errorList; }
- ErrorList const& compilerErrors() const { return m_compiler.errors(); }
+ std::vector<SyntaxTestError> const& errorList() const { return m_errorList; }
- void printExpected(std::ostream& _stream, std::string const& _linePrefix, bool const _formatted = false) const;
-
- void printErrorList(
+ static void printErrorList(
std::ostream& _stream,
- ErrorList const& _errors,
+ std::vector<SyntaxTestError> const& _errors,
std::string const& _linePrefix,
- bool const _ignoreWarnings,
- bool const _lineNumbers,
bool const _formatted = false
- ) const;
+ );
static int registerTests(
boost::unit_test::test_suite& _suite,
@@ -72,16 +76,14 @@ public:
boost::filesystem::path const& _path
);
static bool isTestFilename(boost::filesystem::path const& _filename);
+ static std::string errorMessage(Exception const& _e);
private:
- bool matchesExpectations(ErrorList const& _errors) const;
- static std::string errorMessage(Error const& _e);
static std::string parseSource(std::istream& _stream);
- static std::vector<SyntaxTestExpectation> parseExpectations(std::istream& _stream);
- int offsetToLineNumber(int _location) const;
+ static std::vector<SyntaxTestError> parseExpectations(std::istream& _stream);
std::string m_source;
- std::vector<SyntaxTestExpectation> m_expectations;
- ErrorList m_errorList;
+ std::vector<SyntaxTestError> m_expectations;
+ std::vector<SyntaxTestError> m_errorList;
};
}
diff --git a/test/libsolidity/syntaxTests/arrayLength/array_length_cannot_be_constant_function_parameter.sol b/test/libsolidity/syntaxTests/arrayLength/array_length_cannot_be_constant_function_parameter.sol
new file mode 100644
index 00000000..11d40f26
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/array_length_cannot_be_constant_function_parameter.sol
@@ -0,0 +1,7 @@
+contract C {
+ function f(uint constant LEN) {
+ uint[LEN] a;
+ }
+}
+// ----
+// TypeError: (62-65): Invalid array length, expected integer literal or constant expression.
diff --git a/test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_function.sol b/test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_function.sol
new file mode 100644
index 00000000..92536dd5
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_function.sol
@@ -0,0 +1,8 @@
+contract C {
+ uint constant LEN = 10;
+ function f() public pure {
+ uint[LEN] memory a;
+ a;
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_struct.sol b/test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_struct.sol
new file mode 100644
index 00000000..89e174f2
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_struct.sol
@@ -0,0 +1,7 @@
+contract C {
+ uint constant LEN = 10;
+ struct Test {
+ uint[LEN] ids;
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/arrayLength/can_be_recursive_constant.sol b/test/libsolidity/syntaxTests/arrayLength/can_be_recursive_constant.sol
new file mode 100644
index 00000000..6810a9d6
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/can_be_recursive_constant.sol
@@ -0,0 +1,6 @@
+contract C {
+ uint constant L = 5;
+ uint constant LEN = L + 4 * L;
+ uint[LEN] ids;
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/arrayLength/cannot_be_function.sol b/test/libsolidity/syntaxTests/arrayLength/cannot_be_function.sol
new file mode 100644
index 00000000..ac3abc4c
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/cannot_be_function.sol
@@ -0,0 +1,6 @@
+contract C {
+ function f() {}
+ uint[f] ids;
+}
+// ----
+// TypeError: (42-43): Invalid array length, expected integer literal or constant expression.
diff --git a/test/libsolidity/syntaxTests/arrayLength/cannot_be_function_call.sol b/test/libsolidity/syntaxTests/arrayLength/cannot_be_function_call.sol
new file mode 100644
index 00000000..a6863955
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/cannot_be_function_call.sol
@@ -0,0 +1,7 @@
+contract C {
+ function f(uint x) {}
+ uint constant LEN = f();
+ uint[LEN] ids;
+}
+// ----
+// TypeError: (77-80): Invalid array length, expected integer literal or constant expression.
diff --git a/test/libsolidity/syntaxTests/arrayLength/complex_cyclic_constant.sol b/test/libsolidity/syntaxTests/arrayLength/complex_cyclic_constant.sol
new file mode 100644
index 00000000..254f9f02
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/complex_cyclic_constant.sol
@@ -0,0 +1,10 @@
+contract C {
+ uint constant L2 = LEN - 10;
+ uint constant L1 = L2 / 10;
+ uint constant LEN = 10 + L1 * 5;
+ function f() {
+ uint[LEN] a;
+ }
+}
+// ----
+// TypeError: (36-39): Cyclic constant definition (or maximum recursion depth exhausted).
diff --git a/test/libsolidity/syntaxTests/arrayLength/const_cannot_be_fractional.sol b/test/libsolidity/syntaxTests/arrayLength/const_cannot_be_fractional.sol
new file mode 100644
index 00000000..397bbbcd
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/const_cannot_be_fractional.sol
@@ -0,0 +1,6 @@
+contract C {
+ fixed constant L = 10.5;
+ uint[L] ids;
+}
+// ----
+// TypeError: (51-52): Array with fractional length specified.
diff --git a/test/libsolidity/syntaxTests/arrayLength/constant_var.sol b/test/libsolidity/syntaxTests/arrayLength/constant_var.sol
new file mode 100644
index 00000000..41750250
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/constant_var.sol
@@ -0,0 +1,5 @@
+contract C {
+ uint constant LEN = 10;
+ uint[LEN] ids;
+}
+// ---- \ No newline at end of file
diff --git a/test/libsolidity/syntaxTests/arrayLength/cyclic_constant.sol b/test/libsolidity/syntaxTests/arrayLength/cyclic_constant.sol
new file mode 100644
index 00000000..91ba9045
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/cyclic_constant.sol
@@ -0,0 +1,8 @@
+contract C {
+ uint constant LEN = LEN;
+ function f() {
+ uint[LEN] a;
+ }
+}
+// ----
+// TypeError: (37-40): Cyclic constant definition (or maximum recursion depth exhausted).
diff --git a/test/libsolidity/syntaxTests/arrayLength/inline_array.sol b/test/libsolidity/syntaxTests/arrayLength/inline_array.sol
new file mode 100644
index 00000000..a30745d3
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/inline_array.sol
@@ -0,0 +1,5 @@
+contract C {
+ uint[[2]] a15;
+}
+// ----
+// TypeError: (22-25): Invalid array length, expected integer literal or constant expression.
diff --git a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_1.sol b/test/libsolidity/syntaxTests/arrayLength/invalid_expression_1.sol
new file mode 100644
index 00000000..c92861eb
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/invalid_expression_1.sol
@@ -0,0 +1,5 @@
+contract C {
+ uint[-true] ids;
+}
+// ----
+// TypeError: (22-27): Invalid array length, expected integer literal or constant expression.
diff --git a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_2.sol b/test/libsolidity/syntaxTests/arrayLength/invalid_expression_2.sol
new file mode 100644
index 00000000..92e3c3cf
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/invalid_expression_2.sol
@@ -0,0 +1,5 @@
+contract C {
+ uint[true/1] ids;
+}
+// ----
+// TypeError: (22-28): Invalid array length, expected integer literal or constant expression.
diff --git a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_3.sol b/test/libsolidity/syntaxTests/arrayLength/invalid_expression_3.sol
new file mode 100644
index 00000000..26add45c
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/invalid_expression_3.sol
@@ -0,0 +1,5 @@
+contract C {
+ uint[1/true] ids;
+}
+// ----
+// TypeError: (22-28): Invalid array length, expected integer literal or constant expression.
diff --git a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_4.sol b/test/libsolidity/syntaxTests/arrayLength/invalid_expression_4.sol
new file mode 100644
index 00000000..a0d58f4a
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/invalid_expression_4.sol
@@ -0,0 +1,5 @@
+contract C {
+ uint[1.111111E1111111111111] ids;
+}
+// ----
+// TypeError: (22-44): Invalid array length, expected integer literal or constant expression.
diff --git a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_5.sol b/test/libsolidity/syntaxTests/arrayLength/invalid_expression_5.sol
new file mode 100644
index 00000000..38a80867
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/invalid_expression_5.sol
@@ -0,0 +1,5 @@
+contract C {
+ uint[3/0] ids;
+}
+// ----
+// TypeError: (22-25): Operator / not compatible with types int_const 3 and int_const 0
diff --git a/test/libsolidity/syntaxTests/arrayLength/non_integer_constant_var.sol b/test/libsolidity/syntaxTests/arrayLength/non_integer_constant_var.sol
new file mode 100644
index 00000000..7a853a34
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/non_integer_constant_var.sol
@@ -0,0 +1,6 @@
+contract C {
+ bool constant LEN = true;
+ uint[LEN] ids;
+}
+// ----
+// TypeError: (52-55): Invalid array length, expected integer literal or constant expression.
diff --git a/test/libsolidity/syntaxTests/arrayLength/not_convertible_to_integer.sol b/test/libsolidity/syntaxTests/arrayLength/not_convertible_to_integer.sol
new file mode 100644
index 00000000..b44ccfe9
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/not_convertible_to_integer.sol
@@ -0,0 +1,5 @@
+contract C {
+ uint[true] ids;
+}
+// ----
+// TypeError: (22-26): Invalid array length, expected integer literal or constant expression.
diff --git a/test/libsolidity/syntaxTests/arrayLength/parentheses.sol b/test/libsolidity/syntaxTests/arrayLength/parentheses.sol
new file mode 100644
index 00000000..40f55ad6
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/parentheses.sol
@@ -0,0 +1,25 @@
+contract C {
+ uint constant L1 = (2);
+ uint constant L2 = ((2));
+ uint constant L3 = ((((2))));
+ uint constant L4 = (2 + 1);
+ uint constant L5 = ((2 + 1));
+ uint constant L6 = (((2) + ((1))));
+ uint constant L7 = (2 + 1) / 1;
+ uint constant L8 = (2 + ((1))) / (1);
+ uint[L1] a1;
+ uint[L2] a2;
+ uint[L3] a3;
+ uint[L4] a4;
+ uint[L5] a5;
+ uint[L6] a6;
+ uint[L7] a7;
+ uint[L8] a8;
+ uint[(2)] a9;
+ uint[(2 + 1)] a10;
+ uint[(2 + 1) + 1] a11;
+ uint[((2) + 1) + 1] a12;
+ uint[(2 + 1) + ((1))] a13;
+ uint[(((2) + 1)) + (((1)))] a14;
+ uint[((((2) + 1)) + (((1))))%1] a15;
+}
diff --git a/test/libsolidity/syntaxTests/arrayLength/pure_functions.sol b/test/libsolidity/syntaxTests/arrayLength/pure_functions.sol
new file mode 100644
index 00000000..b620db76
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/pure_functions.sol
@@ -0,0 +1,6 @@
+contract C {
+ uint constant LEN = keccak256(ripemd160(33));
+ uint[LEN] ids;
+}
+// ----
+// TypeError: (72-75): Invalid array length, expected integer literal or constant expression.
diff --git a/test/libsolidity/syntaxTests/arrayLength/too_large.sol b/test/libsolidity/syntaxTests/arrayLength/too_large.sol
new file mode 100644
index 00000000..c90a7494
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/too_large.sol
@@ -0,0 +1,5 @@
+contract C {
+ uint[8**90] ids;
+}
+// ----
+// TypeError: (22-27): Invalid array length, expected integer literal or constant expression.
diff --git a/test/libsolidity/syntaxTests/arrayLength/tuples.sol b/test/libsolidity/syntaxTests/arrayLength/tuples.sol
new file mode 100644
index 00000000..bc10b3b5
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/tuples.sol
@@ -0,0 +1,5 @@
+contract C {
+ uint[(1,2)] a15;
+}
+// ----
+// TypeError: (22-27): Invalid array length, expected integer literal or constant expression.
diff --git a/test/libsolidity/syntaxTests/constants/cyclic_dependency_1.sol b/test/libsolidity/syntaxTests/constants/cyclic_dependency_1.sol
new file mode 100644
index 00000000..cb553fbe
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constants/cyclic_dependency_1.sol
@@ -0,0 +1,5 @@
+contract C {
+ uint constant a = a;
+}
+// ----
+// TypeError: (17-36): The value of the constant a has a cyclic dependency via a.
diff --git a/test/libsolidity/syntaxTests/constants/cyclic_dependency_2.sol b/test/libsolidity/syntaxTests/constants/cyclic_dependency_2.sol
new file mode 100644
index 00000000..00f9bb0f
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constants/cyclic_dependency_2.sol
@@ -0,0 +1,10 @@
+contract C {
+ uint constant a = b * c;
+ uint constant b = 7;
+ uint constant c = b + uint(keccak256(d));
+ uint constant d = 2 + a;
+}
+// ----
+// TypeError: (17-40): The value of the constant a has a cyclic dependency via c.
+// TypeError: (71-111): The value of the constant c has a cyclic dependency via d.
+// TypeError: (117-140): The value of the constant d has a cyclic dependency via a.
diff --git a/test/libsolidity/syntaxTests/constants/cyclic_dependency_3.sol b/test/libsolidity/syntaxTests/constants/cyclic_dependency_3.sol
new file mode 100644
index 00000000..969ed50d
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constants/cyclic_dependency_3.sol
@@ -0,0 +1,11 @@
+contract C {
+ uint constant x = a;
+ uint constant a = b * c;
+ uint constant b = c;
+ uint constant c = b;
+}
+// ----
+// TypeError: (17-36): The value of the constant x has a cyclic dependency via a.
+// TypeError: (42-65): The value of the constant a has a cyclic dependency via b.
+// TypeError: (71-90): The value of the constant b has a cyclic dependency via c.
+// TypeError: (96-115): The value of the constant c has a cyclic dependency via b.
diff --git a/test/libsolidity/syntaxTests/constants/cyclic_dependency_4.sol b/test/libsolidity/syntaxTests/constants/cyclic_dependency_4.sol
new file mode 100644
index 00000000..f01cb98e
--- /dev/null
+++ b/test/libsolidity/syntaxTests/constants/cyclic_dependency_4.sol
@@ -0,0 +1,6 @@
+contract C {
+ uint constant a = b * c;
+ uint constant b = 7;
+ uint constant c = 4 + uint(keccak256(d));
+ uint constant d = 2 + b;
+} \ No newline at end of file
diff --git a/test/libsolidity/syntaxTests/double_stateVariable_declaration.sol b/test/libsolidity/syntaxTests/double_stateVariable_declaration.sol
index c5507b64..fda4a17a 100644
--- a/test/libsolidity/syntaxTests/double_stateVariable_declaration.sol
+++ b/test/libsolidity/syntaxTests/double_stateVariable_declaration.sol
@@ -3,4 +3,4 @@ contract test {
uint128 variable;
}
// ----
-// DeclarationError: Identifier already declared.
+// DeclarationError: (36-52): Identifier already declared.
diff --git a/test/libsolidity/syntaxTests/double_variable_declaration.sol b/test/libsolidity/syntaxTests/double_variable_declaration.sol
index 3349cfec..9ab87959 100644
--- a/test/libsolidity/syntaxTests/double_variable_declaration.sol
+++ b/test/libsolidity/syntaxTests/double_variable_declaration.sol
@@ -5,4 +5,4 @@ contract test {
}
}
// ----
-// DeclarationError: Identifier already declared.
+// DeclarationError: (71-80): Identifier already declared.
diff --git a/test/libsolidity/syntaxTests/double_variable_declaration_050.sol b/test/libsolidity/syntaxTests/double_variable_declaration_050.sol
index 9c2d40d5..2f47e6dc 100644
--- a/test/libsolidity/syntaxTests/double_variable_declaration_050.sol
+++ b/test/libsolidity/syntaxTests/double_variable_declaration_050.sol
@@ -6,6 +6,6 @@ contract test {
}
}
// ----
-// Warning: This declaration shadows an existing declaration.
-// Warning: Unused local variable.
-// Warning: Unused local variable.
+// Warning: (101-110): This declaration shadows an existing declaration.
+// Warning: (76-85): Unused local variable.
+// Warning: (101-110): Unused local variable.
diff --git a/test/libsolidity/syntaxTests/empty_struct.sol b/test/libsolidity/syntaxTests/empty_struct.sol
index dcced618..12655309 100644
--- a/test/libsolidity/syntaxTests/empty_struct.sol
+++ b/test/libsolidity/syntaxTests/empty_struct.sol
@@ -2,4 +2,4 @@ contract test {
struct A {}
}
// ----
-// Warning: Defining empty structs is deprecated.
+// Warning: (17-28): Defining empty structs is deprecated.
diff --git a/test/libsolidity/syntaxTests/empty_struct_050.sol b/test/libsolidity/syntaxTests/empty_struct_050.sol
index dbec93c4..886f1f83 100644
--- a/test/libsolidity/syntaxTests/empty_struct_050.sol
+++ b/test/libsolidity/syntaxTests/empty_struct_050.sol
@@ -3,4 +3,4 @@ contract test {
struct A {}
}
// ----
-// SyntaxError: Defining empty structs is disallowed.
+// SyntaxError: (47-58): Defining empty structs is disallowed.
diff --git a/test/libsolidity/syntaxTests/functionTypes/call_value_on_non_payable_function_type.sol b/test/libsolidity/syntaxTests/functionTypes/call_value_on_non_payable_function_type.sol
new file mode 100644
index 00000000..87c3b05b
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/call_value_on_non_payable_function_type.sol
@@ -0,0 +1,8 @@
+contract C {
+ function (uint) external returns (uint) x;
+ function f() public {
+ x.value(2)();
+ }
+}
+// ----
+// TypeError: (94-101): Member "value" not found or not visible after argument-dependent lookup in function (uint256) external returns (uint256) - did you forget the "payable" modifier?
diff --git a/test/libsolidity/syntaxTests/functionTypes/call_value_on_payable_function_type.sol b/test/libsolidity/syntaxTests/functionTypes/call_value_on_payable_function_type.sol
new file mode 100644
index 00000000..ca2a0196
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/call_value_on_payable_function_type.sol
@@ -0,0 +1,6 @@
+contract C {
+ function (uint) external payable returns (uint) x;
+ function f() public {
+ x.value(2)(1);
+ }
+}
diff --git a/test/libsolidity/syntaxTests/functionTypes/delete_external_function_type_invalid.sol b/test/libsolidity/syntaxTests/functionTypes/delete_external_function_type_invalid.sol
new file mode 100644
index 00000000..2711dae8
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/delete_external_function_type_invalid.sol
@@ -0,0 +1,7 @@
+contract C {
+ function f() public {
+ delete this.f;
+ }
+}
+// ----
+// TypeError: (54-60): Expression has to be an lvalue.
diff --git a/test/libsolidity/syntaxTests/functionTypes/delete_function_type.sol b/test/libsolidity/syntaxTests/functionTypes/delete_function_type.sol
new file mode 100644
index 00000000..a6fe6c22
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/delete_function_type.sol
@@ -0,0 +1,17 @@
+contract C {
+ function(uint) external returns (uint) x;
+ function(uint) internal returns (uint) y;
+ function f() public {
+ delete x;
+ var a = y;
+ delete a;
+ delete y;
+ var c = f;
+ delete c;
+ function(uint) internal returns (uint) g;
+ delete g;
+ }
+}
+// ----
+// Warning: (157-162): Use of the "var" keyword is deprecated.
+// Warning: (212-217): Use of the "var" keyword is deprecated.
diff --git a/test/libsolidity/syntaxTests/functionTypes/delete_function_type_invalid.sol b/test/libsolidity/syntaxTests/functionTypes/delete_function_type_invalid.sol
new file mode 100644
index 00000000..60da19e4
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/delete_function_type_invalid.sol
@@ -0,0 +1,7 @@
+contract C {
+ function f() public {
+ delete f;
+ }
+}
+// ----
+// TypeError: (54-55): Expression has to be an lvalue.
diff --git a/test/libsolidity/syntaxTests/functionTypes/external_function_to_function_type_calldata_parameter.sol b/test/libsolidity/syntaxTests/functionTypes/external_function_to_function_type_calldata_parameter.sol
new file mode 100644
index 00000000..eb4f0693
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/external_function_to_function_type_calldata_parameter.sol
@@ -0,0 +1,10 @@
+// This is a test that checks that the type of the `bytes` parameter is
+// correctly changed from its own type `bytes calldata` to `bytes memory`
+// when converting to a function type.
+contract C {
+ function f(function(bytes memory) pure external /*g*/) pure public { }
+ function callback(bytes) pure external {}
+ function g() view public {
+ f(this.callback);
+ }
+}
diff --git a/test/libsolidity/syntaxTests/functionTypes/external_function_type_public_variable.sol b/test/libsolidity/syntaxTests/functionTypes/external_function_type_public_variable.sol
new file mode 100644
index 00000000..0a6d1e53
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/external_function_type_public_variable.sol
@@ -0,0 +1,11 @@
+contract C {
+ function (uint) external public x;
+
+ function g(uint) public {
+ x = this.g;
+ }
+ function f() public view returns (function(uint) external) {
+ return this.x();
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/functionTypes/external_function_type_returning_internal.sol b/test/libsolidity/syntaxTests/functionTypes/external_function_type_returning_internal.sol
new file mode 100644
index 00000000..8b14d3dc
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/external_function_type_returning_internal.sol
@@ -0,0 +1,5 @@
+contract C {
+ function() external returns (function () internal) x;
+}
+// ----
+// TypeError: (46-67): Internal type cannot be used for external function type.
diff --git a/test/libsolidity/syntaxTests/functionTypes/external_function_type_taking_internal.sol b/test/libsolidity/syntaxTests/functionTypes/external_function_type_taking_internal.sol
new file mode 100644
index 00000000..3e264c8c
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/external_function_type_taking_internal.sol
@@ -0,0 +1,5 @@
+contract C {
+ function(function () internal) external x;
+}
+// ----
+// TypeError: (26-47): Internal type cannot be used for external function type.
diff --git a/test/libsolidity/syntaxTests/functionTypes/external_function_type_to_address.sol b/test/libsolidity/syntaxTests/functionTypes/external_function_type_to_address.sol
new file mode 100644
index 00000000..b86425db
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/external_function_type_to_address.sol
@@ -0,0 +1,5 @@
+contract C {
+ function f() public view returns (address) {
+ return address(this.f);
+ }
+}
diff --git a/test/libsolidity/syntaxTests/functionTypes/external_function_type_to_uint.sol b/test/libsolidity/syntaxTests/functionTypes/external_function_type_to_uint.sol
new file mode 100644
index 00000000..f4287223
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/external_function_type_to_uint.sol
@@ -0,0 +1,7 @@
+contract C {
+ function f() public returns (uint) {
+ return uint(this.f);
+ }
+}
+// ----
+// TypeError: (69-81): Explicit type conversion not allowed from "function () external returns (uint256)" to "uint256".
diff --git a/test/libsolidity/syntaxTests/functionTypes/function_type.sol b/test/libsolidity/syntaxTests/functionTypes/function_type.sol
new file mode 100644
index 00000000..23d50136
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/function_type.sol
@@ -0,0 +1,6 @@
+contract C {
+ function f() pure public {
+ function(uint) returns (uint) x;
+ x;
+ }
+}
diff --git a/test/libsolidity/syntaxTests/functionTypes/function_type_arrays.sol b/test/libsolidity/syntaxTests/functionTypes/function_type_arrays.sol
new file mode 100644
index 00000000..ec23d637
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/function_type_arrays.sol
@@ -0,0 +1,11 @@
+contract C {
+ function(uint) external returns (uint)[] public x;
+ function(uint) internal returns (uint)[10] y;
+ function f() view public {
+ function(uint) returns (uint)[10] memory a;
+ function(uint) returns (uint)[10] storage b = y;
+ function(uint) external returns (uint)[] memory c;
+ c = new function(uint) external returns (uint)[](200);
+ a; b;
+ }
+}
diff --git a/test/libsolidity/syntaxTests/functionTypes/function_type_constructor.sol b/test/libsolidity/syntaxTests/functionTypes/function_type_constructor.sol
new file mode 100644
index 00000000..95ebc179
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/function_type_constructor.sol
@@ -0,0 +1,7 @@
+contract C {
+ // Fool parser into parsing a constructor as a function type.
+ constructor() x;
+}
+// ----
+// Warning: (83-99): Modifiers of functions without implementation are ignored.
+// DeclarationError: (97-98): Undeclared identifier.
diff --git a/test/libsolidity/syntaxTests/functionTypes/function_type_constructor_local.sol b/test/libsolidity/syntaxTests/functionTypes/function_type_constructor_local.sol
new file mode 100644
index 00000000..b7763d28
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/function_type_constructor_local.sol
@@ -0,0 +1,8 @@
+contract C {
+ // Fool parser into parsing a constructor as a function type.
+ function f() {
+ constructor() x;
+ }
+}
+// ----
+// ParserError: (118-118): Expected token Semicolon got 'Identifier'
diff --git a/test/libsolidity/syntaxTests/functionTypes/function_type_internal_public_variable.sol b/test/libsolidity/syntaxTests/functionTypes/function_type_internal_public_variable.sol
new file mode 100644
index 00000000..4eb53227
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/function_type_internal_public_variable.sol
@@ -0,0 +1,5 @@
+contract C {
+ function(bytes memory) internal public a;
+}
+// ----
+// TypeError: (17-57): Internal or recursive type is not allowed for public state variables.
diff --git a/test/libsolidity/syntaxTests/functionTypes/function_type_parameter.sol b/test/libsolidity/syntaxTests/functionTypes/function_type_parameter.sol
new file mode 100644
index 00000000..da66ec8a
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/function_type_parameter.sol
@@ -0,0 +1,7 @@
+contract C {
+ uint x;
+ function f(function(uint) external returns (uint) g) public returns (function(uint) external returns (uint)) {
+ x = 2;
+ return g;
+ }
+}
diff --git a/test/libsolidity/syntaxTests/functionTypes/function_type_returned.sol b/test/libsolidity/syntaxTests/functionTypes/function_type_returned.sol
new file mode 100644
index 00000000..9cd313c8
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/function_type_returned.sol
@@ -0,0 +1,5 @@
+contract C {
+ function f() public pure returns (function(uint) pure external returns (uint) g) {
+ return g;
+ }
+}
diff --git a/test/libsolidity/syntaxTests/functionTypes/function_type_variable_external_internal.sol b/test/libsolidity/syntaxTests/functionTypes/function_type_variable_external_internal.sol
new file mode 100644
index 00000000..f0240472
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/function_type_variable_external_internal.sol
@@ -0,0 +1,6 @@
+contract test {
+ function fa(bytes memory) public { }
+ function(bytes memory) external internal a = fa;
+}
+// ----
+// TypeError: (106-108): Type function (bytes memory) is not implicitly convertible to expected type function (bytes memory) external.
diff --git a/test/libsolidity/syntaxTests/functionTypes/function_types_internal_visibility_error.sol b/test/libsolidity/syntaxTests/functionTypes/function_types_internal_visibility_error.sol
new file mode 100644
index 00000000..36206d63
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/function_types_internal_visibility_error.sol
@@ -0,0 +1,7 @@
+contract C {
+ // This is an error, you should explicitly use
+ // `external public` to fix it - `internal public` does not exist.
+ function(bytes memory) public a;
+}
+// ----
+// TypeError: (139-170): Invalid visibility, can only be "external" or "internal".
diff --git a/test/libsolidity/syntaxTests/functionTypes/function_types_variable_visibility.sol b/test/libsolidity/syntaxTests/functionTypes/function_types_variable_visibility.sol
new file mode 100644
index 00000000..91c2420a
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/function_types_variable_visibility.sol
@@ -0,0 +1,9 @@
+contract C {
+ function(bytes memory) a1;
+ function(bytes memory) internal b1;
+ function(bytes memory) internal internal b2;
+ function(bytes memory) external c1;
+ function(bytes memory) external internal c2;
+ function(bytes memory) external public c3;
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/functionTypes/internal_function_as_external_parameter.sol b/test/libsolidity/syntaxTests/functionTypes/internal_function_as_external_parameter.sol
new file mode 100644
index 00000000..fa92d559
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/internal_function_as_external_parameter.sol
@@ -0,0 +1,8 @@
+// It should not be possible to give internal functions
+// as parameters to external functions.
+contract C {
+ function f(function(uint) internal returns (uint) x) public {
+ }
+}
+// ----
+// TypeError: (124-164): Internal or recursive type is not allowed for public or external functions.
diff --git a/test/libsolidity/syntaxTests/functionTypes/internal_function_as_external_parameter_in_library_external.sol b/test/libsolidity/syntaxTests/functionTypes/internal_function_as_external_parameter_in_library_external.sol
new file mode 100644
index 00000000..b37fb285
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/internal_function_as_external_parameter_in_library_external.sol
@@ -0,0 +1,6 @@
+library L {
+ function f(function(uint) internal returns (uint) x) public {
+ }
+}
+// ----
+// TypeError: (27-67): Internal or recursive type is not allowed for public or external functions.
diff --git a/test/libsolidity/syntaxTests/functionTypes/internal_function_as_external_parameter_in_library_internal.sol b/test/libsolidity/syntaxTests/functionTypes/internal_function_as_external_parameter_in_library_internal.sol
new file mode 100644
index 00000000..7ffa447e
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/internal_function_as_external_parameter_in_library_internal.sol
@@ -0,0 +1,4 @@
+library L {
+ function f(function(uint) internal returns (uint) /*x*/) pure internal {
+ }
+}
diff --git a/test/libsolidity/syntaxTests/functionTypes/internal_function_returned_from_public_function.sol b/test/libsolidity/syntaxTests/functionTypes/internal_function_returned_from_public_function.sol
new file mode 100644
index 00000000..41fcd0a4
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/internal_function_returned_from_public_function.sol
@@ -0,0 +1,7 @@
+// It should not be possible to return internal functions from external functions.
+contract C {
+ function f() public returns (function(uint) internal returns (uint) x) {
+ }
+}
+// ----
+// TypeError: (129-169): Internal or recursive type is not allowed for public or external functions.
diff --git a/test/libsolidity/syntaxTests/functionTypes/internal_function_type_to_address.sol b/test/libsolidity/syntaxTests/functionTypes/internal_function_type_to_address.sol
new file mode 100644
index 00000000..b75a0d43
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/internal_function_type_to_address.sol
@@ -0,0 +1,7 @@
+contract C {
+ function f() public returns (address) {
+ return address(f);
+ }
+}
+// ----
+// TypeError: (72-82): Explicit type conversion not allowed from "function () returns (address)" to "address".
diff --git a/test/libsolidity/syntaxTests/functionTypes/payable_internal_function_type.sol b/test/libsolidity/syntaxTests/functionTypes/payable_internal_function_type.sol
new file mode 100644
index 00000000..a7cb9d92
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/payable_internal_function_type.sol
@@ -0,0 +1,5 @@
+contract C {
+ function (uint) internal payable returns (uint) x;
+}
+// ----
+// TypeError: (17-66): Only external function types can be payable.
diff --git a/test/libsolidity/syntaxTests/functionTypes/payable_internal_function_type_is_not_fatal.sol b/test/libsolidity/syntaxTests/functionTypes/payable_internal_function_type_is_not_fatal.sol
new file mode 100644
index 00000000..5c6dc056
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/payable_internal_function_type_is_not_fatal.sol
@@ -0,0 +1,9 @@
+contract C {
+ function (uint) internal payable returns (uint) x;
+
+ function g() public {
+ x = g;
+ }
+}
+// ----
+// TypeError: (17-66): Only external function types can be payable.
diff --git a/test/libsolidity/syntaxTests/functionTypes/private_function_type.sol b/test/libsolidity/syntaxTests/functionTypes/private_function_type.sol
new file mode 100644
index 00000000..9d4f0a09
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/private_function_type.sol
@@ -0,0 +1,7 @@
+contract C {
+ function f() public {
+ function(uint) private returns (uint) x;
+ }
+}
+// ----
+// TypeError: (47-86): Invalid visibility, can only be "external" or "internal".
diff --git a/test/libsolidity/syntaxTests/functionTypes/public_function_type.sol b/test/libsolidity/syntaxTests/functionTypes/public_function_type.sol
new file mode 100644
index 00000000..756766d3
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/public_function_type.sol
@@ -0,0 +1,7 @@
+contract C {
+ function f() public {
+ function(uint) public returns (uint) x;
+ }
+}
+// ----
+// TypeError: (47-85): Invalid visibility, can only be "external" or "internal".
diff --git a/test/libsolidity/syntaxTests/functionTypes/valid_function_type_variables.sol b/test/libsolidity/syntaxTests/functionTypes/valid_function_type_variables.sol
new file mode 100644
index 00000000..10c6767c
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/valid_function_type_variables.sol
@@ -0,0 +1,23 @@
+contract test {
+ function fa(uint) {}
+ function fb(uint) internal {}
+ function fc(uint) internal {}
+ function fd(uint) external {}
+ function fe(uint) external {}
+ function ff(uint) internal {}
+ function fg(uint) internal pure {}
+ function fh(uint) pure internal {}
+
+ function(uint) a = fa;
+ function(uint) internal b = fb; // (explicit internal applies to the function type)
+ function(uint) internal internal c = fc;
+ function(uint) external d = this.fd;
+ function(uint) external internal e = this.fe;
+ function(uint) internal public f = ff;
+ function(uint) internal pure public g = fg;
+ function(uint) pure internal public h = fh;
+}
+// ----
+// TypeError: (545-582): Internal or recursive type is not allowed for public state variables.
+// TypeError: (588-630): Internal or recursive type is not allowed for public state variables.
+// TypeError: (636-678): Internal or recursive type is not allowed for public state variables.
diff --git a/test/libsolidity/syntaxTests/functionTypes/warn_function_type_parameters_with_names.sol b/test/libsolidity/syntaxTests/functionTypes/warn_function_type_parameters_with_names.sol
new file mode 100644
index 00000000..072c7eb7
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/warn_function_type_parameters_with_names.sol
@@ -0,0 +1,5 @@
+contract C {
+ function(uint a) f;
+}
+// ----
+// Warning: (26-32): Naming function type parameters is deprecated.
diff --git a/test/libsolidity/syntaxTests/functionTypes/warn_function_type_return_parameters_with_names.sol b/test/libsolidity/syntaxTests/functionTypes/warn_function_type_return_parameters_with_names.sol
new file mode 100644
index 00000000..67a74e54
--- /dev/null
+++ b/test/libsolidity/syntaxTests/functionTypes/warn_function_type_return_parameters_with_names.sol
@@ -0,0 +1,5 @@
+contract C {
+ function(uint) returns (bool ret) f;
+}
+// ----
+// Warning: (41-49): Naming function type return parameters is deprecated.
diff --git a/test/libsolidity/syntaxTests/inheritance/allow_empty_duplicated_super_constructor_call.sol b/test/libsolidity/syntaxTests/inheritance/allow_empty_duplicated_super_constructor_call.sol
new file mode 100644
index 00000000..ce9d5f5f
--- /dev/null
+++ b/test/libsolidity/syntaxTests/inheritance/allow_empty_duplicated_super_constructor_call.sol
@@ -0,0 +1,2 @@
+contract A { constructor() public { } }
+contract B is A { constructor() A() public { } }
diff --git a/test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses.sol b/test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses.sol
index 76df0657..0b18b995 100644
--- a/test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses.sol
+++ b/test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses.sol
@@ -1,6 +1,7 @@
contract Base {
- function Base(uint) public {}
+ constructor(uint) public {}
}
contract Derived is Base(2) { }
contract Derived2 is Base(), Derived() { }
-contract Derived3 is Base, Derived {}
+// ----
+// Warning: (101-107): Wrong argument count for constructor call: 0 arguments given but expected 1.
diff --git a/test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses_V050.sol b/test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses_V050.sol
new file mode 100644
index 00000000..db04ab8c
--- /dev/null
+++ b/test/libsolidity/syntaxTests/inheritance/base_arguments_empty_parentheses_V050.sol
@@ -0,0 +1,9 @@
+pragma experimental "v0.5.0";
+
+contract Base {
+ constructor(uint) public {}
+}
+contract Derived is Base(2) { }
+contract Derived2 is Base(), Derived() { }
+// ----
+// TypeError: (132-138): Wrong argument count for constructor call: 0 arguments given but expected 1.
diff --git a/test/libsolidity/syntaxTests/inheritance/base_arguments_multiple_inheritance.sol b/test/libsolidity/syntaxTests/inheritance/base_arguments_multiple_inheritance.sol
new file mode 100644
index 00000000..015b33e5
--- /dev/null
+++ b/test/libsolidity/syntaxTests/inheritance/base_arguments_multiple_inheritance.sol
@@ -0,0 +1,9 @@
+contract Base {
+ constructor(uint) public { }
+}
+contract Base1 is Base(3) {}
+contract Derived is Base, Base1 {
+ constructor(uint i) Base(i) public {}
+}
+// ----
+// Warning: (138-145): Base constructor arguments given twice.
diff --git a/test/libsolidity/syntaxTests/inheritance/base_arguments_no_parentheses.sol b/test/libsolidity/syntaxTests/inheritance/base_arguments_no_parentheses.sol
new file mode 100644
index 00000000..24cca8f0
--- /dev/null
+++ b/test/libsolidity/syntaxTests/inheritance/base_arguments_no_parentheses.sol
@@ -0,0 +1,5 @@
+contract Base {
+ constructor(uint) public {}
+}
+contract Derived is Base(2) { }
+contract Derived2 is Base, Derived {}
diff --git a/test/libsolidity/syntaxTests/inheritance/disallow_modifier_style_without_parentheses.sol b/test/libsolidity/syntaxTests/inheritance/disallow_modifier_style_without_parentheses.sol
new file mode 100644
index 00000000..6cf68d2a
--- /dev/null
+++ b/test/libsolidity/syntaxTests/inheritance/disallow_modifier_style_without_parentheses.sol
@@ -0,0 +1,4 @@
+contract A { constructor() public { } }
+contract B is A { constructor() A public { } }
+// ----
+// Warning: (72-73): Modifier-style base constructor call without arguments.
diff --git a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/ancestor.sol b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/ancestor.sol
new file mode 100644
index 00000000..24cff54d
--- /dev/null
+++ b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/ancestor.sol
@@ -0,0 +1,5 @@
+contract A { constructor(uint) public { } }
+contract B is A(2) { constructor() public { } }
+contract C is B { constructor() A(3) public { } }
+// ----
+// Warning: (125-129): Base constructor arguments given twice.
diff --git a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/ancestor_V050.sol b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/ancestor_V050.sol
new file mode 100644
index 00000000..8d5df5bf
--- /dev/null
+++ b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/ancestor_V050.sol
@@ -0,0 +1,7 @@
+pragma experimental "v0.5.0";
+
+contract A { constructor(uint) public { } }
+contract B is A(2) { constructor() public { } }
+contract C is B { constructor() A(3) public { } }
+// ----
+// DeclarationError: (156-160): Base constructor arguments given twice.
diff --git a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base.sol b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base.sol
new file mode 100644
index 00000000..9ceaea5e
--- /dev/null
+++ b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base.sol
@@ -0,0 +1,4 @@
+contract A { constructor(uint) public { } }
+contract B is A(2) { constructor() A(3) public { } }
+// ----
+// Warning: (79-83): Base constructor arguments given twice.
diff --git a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_V050.sol b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_V050.sol
new file mode 100644
index 00000000..f9325f99
--- /dev/null
+++ b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_V050.sol
@@ -0,0 +1,6 @@
+pragma experimental "v0.5.0";
+
+contract A { constructor(uint) public { } }
+contract B is A(2) { constructor() A(3) public { } }
+// ----
+// DeclarationError: (110-114): Base constructor arguments given twice.
diff --git a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi.sol b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi.sol
new file mode 100644
index 00000000..e5c2aa36
--- /dev/null
+++ b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi.sol
@@ -0,0 +1,7 @@
+contract C { constructor(uint) public {} }
+contract A is C(2) {}
+contract B is C(2) {}
+contract D is A, B { constructor() C(3) public {} }
+// ----
+// Warning: (122-126): Base constructor arguments given twice.
+// Warning: (122-126): Base constructor arguments given twice.
diff --git a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor.sol b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor.sol
new file mode 100644
index 00000000..1abf2992
--- /dev/null
+++ b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor.sol
@@ -0,0 +1,6 @@
+contract C { constructor(uint) public {} }
+contract A is C(2) {}
+contract B is C(2) {}
+contract D is A, B {}
+// ----
+// Warning: (87-108): Base constructor arguments given twice.
diff --git a/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor_modifier_style.sol b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor_modifier_style.sol
new file mode 100644
index 00000000..e15242db
--- /dev/null
+++ b/test/libsolidity/syntaxTests/inheritance/duplicated_constructor_call/base_multi_no_constructor_modifier_style.sol
@@ -0,0 +1,6 @@
+contract C { constructor(uint) public {} }
+contract A is C { constructor() C(2) public {} }
+contract B is C { constructor() C(2) public {} }
+contract D is A, B { }
+// ----
+// Warning: (141-163): Base constructor arguments given twice.
diff --git a/test/libsolidity/syntaxTests/inheritance/too_few_base_arguments.sol b/test/libsolidity/syntaxTests/inheritance/too_few_base_arguments.sol
index 82aba308..c55c41f2 100644
--- a/test/libsolidity/syntaxTests/inheritance/too_few_base_arguments.sol
+++ b/test/libsolidity/syntaxTests/inheritance/too_few_base_arguments.sol
@@ -1,10 +1,10 @@
contract Base {
- function Base(uint, uint) public {}
+ constructor(uint, uint) public {}
}
contract Derived is Base(2) { }
contract Derived2 is Base {
- function Derived2() Base(2) public { }
+ constructor() Base(2) public { }
}
// ----
-// TypeError: Wrong argument count for constructor call: 1 arguments given but expected 2.
-// TypeError: Wrong argument count for modifier invocation: 1 arguments given but expected 2.
+// TypeError: (74-81): Wrong argument count for constructor call: 1 arguments given but expected 2.
+// TypeError: (130-137): Wrong argument count for modifier invocation: 1 arguments given but expected 2.
diff --git a/test/libsolidity/syntaxTests/literal_comparisons.sol b/test/libsolidity/syntaxTests/literal_comparisons.sol
new file mode 100644
index 00000000..dd2afcaa
--- /dev/null
+++ b/test/libsolidity/syntaxTests/literal_comparisons.sol
@@ -0,0 +1,7 @@
+contract test {
+ function f(int8 x) public pure {
+ if (x == 1) {}
+ if (1 == x) {}
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/modifiers/base_constructor_double_invocation.sol b/test/libsolidity/syntaxTests/modifiers/base_constructor_double_invocation.sol
new file mode 100644
index 00000000..bdbab5d8
--- /dev/null
+++ b/test/libsolidity/syntaxTests/modifiers/base_constructor_double_invocation.sol
@@ -0,0 +1,7 @@
+contract C { constructor(uint a) public {} }
+contract B is C {
+ constructor() C(2) C(2) public {}
+}
+// ----
+// Warning: (81-85): Base constructor arguments given twice.
+// DeclarationError: (86-90): Base constructor already provided.
diff --git a/test/libsolidity/syntaxTests/modifiers/constructor_call_invalid_arg_count.sol b/test/libsolidity/syntaxTests/modifiers/constructor_call_invalid_arg_count.sol
new file mode 100644
index 00000000..4a2b5c4a
--- /dev/null
+++ b/test/libsolidity/syntaxTests/modifiers/constructor_call_invalid_arg_count.sol
@@ -0,0 +1,9 @@
+// This caused a segfault in an earlier version
+contract C {
+ constructor() public {}
+}
+contract D is C {
+ constructor() C(5) public {}
+}
+// ----
+// TypeError: (127-131): Wrong argument count for modifier invocation: 1 arguments given but expected 0.
diff --git a/test/libsolidity/syntaxTests/modifiers/function_modifier_double_invocation.sol b/test/libsolidity/syntaxTests/modifiers/function_modifier_double_invocation.sol
new file mode 100644
index 00000000..75624192
--- /dev/null
+++ b/test/libsolidity/syntaxTests/modifiers/function_modifier_double_invocation.sol
@@ -0,0 +1,4 @@
+contract B {
+ function f(uint x) mod(x) mod(2) public pure { }
+ modifier mod(uint a) { if (a > 0) _; }
+}
diff --git a/test/libsolidity/syntaxTests/modifiers/function_modifier_invocation.sol b/test/libsolidity/syntaxTests/modifiers/function_modifier_invocation.sol
new file mode 100644
index 00000000..e15fcf49
--- /dev/null
+++ b/test/libsolidity/syntaxTests/modifiers/function_modifier_invocation.sol
@@ -0,0 +1,5 @@
+contract B {
+ function f() mod1(2, true) mod2("0123456") pure public { }
+ modifier mod1(uint a, bool b) { if (b) _; }
+ modifier mod2(bytes7 a) { while (a == "1234567") _; }
+}
diff --git a/test/libsolidity/syntaxTests/modifiers/function_modifier_invocation_local_variables.sol b/test/libsolidity/syntaxTests/modifiers/function_modifier_invocation_local_variables.sol
new file mode 100644
index 00000000..00031924
--- /dev/null
+++ b/test/libsolidity/syntaxTests/modifiers/function_modifier_invocation_local_variables.sol
@@ -0,0 +1,4 @@
+contract B {
+ function f() mod(x) pure public { uint x = 7; }
+ modifier mod(uint a) { if (a > 0) _; }
+}
diff --git a/test/libsolidity/syntaxTests/modifiers/function_modifier_invocation_local_variables050.sol b/test/libsolidity/syntaxTests/modifiers/function_modifier_invocation_local_variables050.sol
new file mode 100644
index 00000000..c19ccf2c
--- /dev/null
+++ b/test/libsolidity/syntaxTests/modifiers/function_modifier_invocation_local_variables050.sol
@@ -0,0 +1,7 @@
+pragma experimental "v0.5.0";
+contract B {
+ function f() mod(x) pure public { uint x = 7; }
+ modifier mod(uint a) { if (a > 0) _; }
+}
+// ----
+// DeclarationError: (64-65): Undeclared identifier.
diff --git a/test/libsolidity/syntaxTests/modifiers/function_modifier_invocation_parameters.sol b/test/libsolidity/syntaxTests/modifiers/function_modifier_invocation_parameters.sol
new file mode 100644
index 00000000..de2a8f48
--- /dev/null
+++ b/test/libsolidity/syntaxTests/modifiers/function_modifier_invocation_parameters.sol
@@ -0,0 +1,5 @@
+contract B {
+ function f(uint8 a) mod1(a, true) mod2(r) pure public returns (bytes7 r) { }
+ modifier mod1(uint a, bool b) { if (b) _; }
+ modifier mod2(bytes7 a) { while (a == "1234567") _; }
+}
diff --git a/test/libsolidity/syntaxTests/modifiers/function_overrides_modifier.sol b/test/libsolidity/syntaxTests/modifiers/function_overrides_modifier.sol
new file mode 100644
index 00000000..a64c2790
--- /dev/null
+++ b/test/libsolidity/syntaxTests/modifiers/function_overrides_modifier.sol
@@ -0,0 +1,5 @@
+contract A { function mod(uint a) public { } }
+contract B is A { modifier mod(uint a) { _; } }
+// ----
+// DeclarationError: (65-92): Identifier already declared.
+// TypeError: (65-92): Override changes function to modifier.
diff --git a/test/libsolidity/syntaxTests/modifiers/illegal_modifier_override.sol b/test/libsolidity/syntaxTests/modifiers/illegal_modifier_override.sol
new file mode 100644
index 00000000..958be686
--- /dev/null
+++ b/test/libsolidity/syntaxTests/modifiers/illegal_modifier_override.sol
@@ -0,0 +1,4 @@
+contract A { modifier mod(uint a) { _; } }
+contract B is A { modifier mod(uint8 a) { _; } }
+// ----
+// TypeError: (61-89): Override changes modifier signature.
diff --git a/test/libsolidity/syntaxTests/modifiers/invalid_function_modifier_type.sol b/test/libsolidity/syntaxTests/modifiers/invalid_function_modifier_type.sol
new file mode 100644
index 00000000..c1e3108b
--- /dev/null
+++ b/test/libsolidity/syntaxTests/modifiers/invalid_function_modifier_type.sol
@@ -0,0 +1,6 @@
+contract B {
+ function f() mod1(true) public { }
+ modifier mod1(uint a) { if (a > 0) _; }
+}
+// ----
+// TypeError: (35-39): Invalid type for argument in modifier invocation. Invalid implicit conversion from bool to uint256 requested.
diff --git a/test/libsolidity/syntaxTests/modifiers/legal_modifier_override.sol b/test/libsolidity/syntaxTests/modifiers/legal_modifier_override.sol
new file mode 100644
index 00000000..51c3fd80
--- /dev/null
+++ b/test/libsolidity/syntaxTests/modifiers/legal_modifier_override.sol
@@ -0,0 +1,2 @@
+contract A { modifier mod(uint a) { _; } }
+contract B is A { modifier mod(uint a) { _; } }
diff --git a/test/libsolidity/syntaxTests/modifiers/modifier_overrides_function.sol b/test/libsolidity/syntaxTests/modifiers/modifier_overrides_function.sol
new file mode 100644
index 00000000..a43646c3
--- /dev/null
+++ b/test/libsolidity/syntaxTests/modifiers/modifier_overrides_function.sol
@@ -0,0 +1,5 @@
+contract A { modifier mod(uint a) { _; } }
+contract B is A { function mod(uint a) public { } }
+// ----
+// DeclarationError: (61-92): Identifier already declared.
+// TypeError: (13-40): Override changes modifier to function.
diff --git a/test/libsolidity/syntaxTests/modifiers/modifier_returns_value.sol b/test/libsolidity/syntaxTests/modifiers/modifier_returns_value.sol
new file mode 100644
index 00000000..d22e836c
--- /dev/null
+++ b/test/libsolidity/syntaxTests/modifiers/modifier_returns_value.sol
@@ -0,0 +1,6 @@
+contract A {
+ function f(uint a) mod(2) public returns (uint r) { }
+ modifier mod(uint a) { _; return 7; }
+}
+// ----
+// TypeError: (101-109): Return arguments not allowed.
diff --git a/test/libsolidity/syntaxTests/modifiers/modifier_without_underscore.sol b/test/libsolidity/syntaxTests/modifiers/modifier_without_underscore.sol
new file mode 100644
index 00000000..6198d3c5
--- /dev/null
+++ b/test/libsolidity/syntaxTests/modifiers/modifier_without_underscore.sol
@@ -0,0 +1,5 @@
+contract test {
+ modifier m() {}
+}
+// ----
+// SyntaxError: (33-35): Modifier body does not contain '_'.
diff --git a/test/libsolidity/syntaxTests/modifiers/modifiers_on_abstract_functions_050.sol b/test/libsolidity/syntaxTests/modifiers/modifiers_on_abstract_functions_050.sol
new file mode 100644
index 00000000..af1babbc
--- /dev/null
+++ b/test/libsolidity/syntaxTests/modifiers/modifiers_on_abstract_functions_050.sol
@@ -0,0 +1,10 @@
+pragma experimental "v0.5.0";
+contract C
+{
+ modifier only_owner() { _; }
+ function foo() only_owner public;
+ function bar() public only_owner;
+}
+// ----
+// SyntaxError: (80-113): Functions without implementation cannot have modifiers.
+// SyntaxError: (118-151): Functions without implementation cannot have modifiers.
diff --git a/test/libsolidity/syntaxTests/modifiers/modifiers_on_abstract_functions_no_parser_error.sol b/test/libsolidity/syntaxTests/modifiers/modifiers_on_abstract_functions_no_parser_error.sol
new file mode 100644
index 00000000..e18c5cf9
--- /dev/null
+++ b/test/libsolidity/syntaxTests/modifiers/modifiers_on_abstract_functions_no_parser_error.sol
@@ -0,0 +1,13 @@
+// Previous versions of Solidity turned this
+// into a parser error (they wrongly recognized
+// these functions as state variables of
+// function type).
+contract C
+{
+ modifier only_owner() { _; }
+ function foo() only_owner public;
+ function bar() public only_owner;
+}
+// ----
+// Warning: (203-236): Modifiers of functions without implementation are ignored.
+// Warning: (241-274): Modifiers of functions without implementation are ignored.
diff --git a/test/libsolidity/syntaxTests/more_than_256_declarationerrors.sol b/test/libsolidity/syntaxTests/more_than_256_declarationerrors.sol
new file mode 100644
index 00000000..2d75f29b
--- /dev/null
+++ b/test/libsolidity/syntaxTests/more_than_256_declarationerrors.sol
@@ -0,0 +1,524 @@
+contract C {
+ function f() {
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ b = 5;
+ }
+}
+// ----
+// DeclarationError: (34-35): Undeclared identifier.
+// DeclarationError: (45-46): Undeclared identifier.
+// DeclarationError: (56-57): Undeclared identifier.
+// DeclarationError: (67-68): Undeclared identifier.
+// DeclarationError: (78-79): Undeclared identifier.
+// DeclarationError: (89-90): Undeclared identifier.
+// DeclarationError: (100-101): Undeclared identifier.
+// DeclarationError: (111-112): Undeclared identifier.
+// DeclarationError: (122-123): Undeclared identifier.
+// DeclarationError: (133-134): Undeclared identifier.
+// DeclarationError: (144-145): Undeclared identifier.
+// DeclarationError: (155-156): Undeclared identifier.
+// DeclarationError: (166-167): Undeclared identifier.
+// DeclarationError: (177-178): Undeclared identifier.
+// DeclarationError: (188-189): Undeclared identifier.
+// DeclarationError: (199-200): Undeclared identifier.
+// DeclarationError: (210-211): Undeclared identifier.
+// DeclarationError: (221-222): Undeclared identifier.
+// DeclarationError: (232-233): Undeclared identifier.
+// DeclarationError: (243-244): Undeclared identifier.
+// DeclarationError: (254-255): Undeclared identifier.
+// DeclarationError: (265-266): Undeclared identifier.
+// DeclarationError: (276-277): Undeclared identifier.
+// DeclarationError: (287-288): Undeclared identifier.
+// DeclarationError: (298-299): Undeclared identifier.
+// DeclarationError: (309-310): Undeclared identifier.
+// DeclarationError: (320-321): Undeclared identifier.
+// DeclarationError: (331-332): Undeclared identifier.
+// DeclarationError: (342-343): Undeclared identifier.
+// DeclarationError: (353-354): Undeclared identifier.
+// DeclarationError: (364-365): Undeclared identifier.
+// DeclarationError: (375-376): Undeclared identifier.
+// DeclarationError: (386-387): Undeclared identifier.
+// DeclarationError: (397-398): Undeclared identifier.
+// DeclarationError: (408-409): Undeclared identifier.
+// DeclarationError: (419-420): Undeclared identifier.
+// DeclarationError: (430-431): Undeclared identifier.
+// DeclarationError: (441-442): Undeclared identifier.
+// DeclarationError: (452-453): Undeclared identifier.
+// DeclarationError: (463-464): Undeclared identifier.
+// DeclarationError: (474-475): Undeclared identifier.
+// DeclarationError: (485-486): Undeclared identifier.
+// DeclarationError: (496-497): Undeclared identifier.
+// DeclarationError: (507-508): Undeclared identifier.
+// DeclarationError: (518-519): Undeclared identifier.
+// DeclarationError: (529-530): Undeclared identifier.
+// DeclarationError: (540-541): Undeclared identifier.
+// DeclarationError: (551-552): Undeclared identifier.
+// DeclarationError: (562-563): Undeclared identifier.
+// DeclarationError: (573-574): Undeclared identifier.
+// DeclarationError: (584-585): Undeclared identifier.
+// DeclarationError: (595-596): Undeclared identifier.
+// DeclarationError: (606-607): Undeclared identifier.
+// DeclarationError: (617-618): Undeclared identifier.
+// DeclarationError: (628-629): Undeclared identifier.
+// DeclarationError: (639-640): Undeclared identifier.
+// DeclarationError: (650-651): Undeclared identifier.
+// DeclarationError: (661-662): Undeclared identifier.
+// DeclarationError: (672-673): Undeclared identifier.
+// DeclarationError: (683-684): Undeclared identifier.
+// DeclarationError: (694-695): Undeclared identifier.
+// DeclarationError: (705-706): Undeclared identifier.
+// DeclarationError: (716-717): Undeclared identifier.
+// DeclarationError: (727-728): Undeclared identifier.
+// DeclarationError: (738-739): Undeclared identifier.
+// DeclarationError: (749-750): Undeclared identifier.
+// DeclarationError: (760-761): Undeclared identifier.
+// DeclarationError: (771-772): Undeclared identifier.
+// DeclarationError: (782-783): Undeclared identifier.
+// DeclarationError: (793-794): Undeclared identifier.
+// DeclarationError: (804-805): Undeclared identifier.
+// DeclarationError: (815-816): Undeclared identifier.
+// DeclarationError: (826-827): Undeclared identifier.
+// DeclarationError: (837-838): Undeclared identifier.
+// DeclarationError: (848-849): Undeclared identifier.
+// DeclarationError: (859-860): Undeclared identifier.
+// DeclarationError: (870-871): Undeclared identifier.
+// DeclarationError: (881-882): Undeclared identifier.
+// DeclarationError: (892-893): Undeclared identifier.
+// DeclarationError: (903-904): Undeclared identifier.
+// DeclarationError: (914-915): Undeclared identifier.
+// DeclarationError: (925-926): Undeclared identifier.
+// DeclarationError: (936-937): Undeclared identifier.
+// DeclarationError: (947-948): Undeclared identifier.
+// DeclarationError: (958-959): Undeclared identifier.
+// DeclarationError: (969-970): Undeclared identifier.
+// DeclarationError: (980-981): Undeclared identifier.
+// DeclarationError: (991-992): Undeclared identifier.
+// DeclarationError: (1002-1003): Undeclared identifier.
+// DeclarationError: (1013-1014): Undeclared identifier.
+// DeclarationError: (1024-1025): Undeclared identifier.
+// DeclarationError: (1035-1036): Undeclared identifier.
+// DeclarationError: (1046-1047): Undeclared identifier.
+// DeclarationError: (1057-1058): Undeclared identifier.
+// DeclarationError: (1068-1069): Undeclared identifier.
+// DeclarationError: (1079-1080): Undeclared identifier.
+// DeclarationError: (1090-1091): Undeclared identifier.
+// DeclarationError: (1101-1102): Undeclared identifier.
+// DeclarationError: (1112-1113): Undeclared identifier.
+// DeclarationError: (1123-1124): Undeclared identifier.
+// DeclarationError: (1134-1135): Undeclared identifier.
+// DeclarationError: (1145-1146): Undeclared identifier.
+// DeclarationError: (1156-1157): Undeclared identifier.
+// DeclarationError: (1167-1168): Undeclared identifier.
+// DeclarationError: (1178-1179): Undeclared identifier.
+// DeclarationError: (1189-1190): Undeclared identifier.
+// DeclarationError: (1200-1201): Undeclared identifier.
+// DeclarationError: (1211-1212): Undeclared identifier.
+// DeclarationError: (1222-1223): Undeclared identifier.
+// DeclarationError: (1233-1234): Undeclared identifier.
+// DeclarationError: (1244-1245): Undeclared identifier.
+// DeclarationError: (1255-1256): Undeclared identifier.
+// DeclarationError: (1266-1267): Undeclared identifier.
+// DeclarationError: (1277-1278): Undeclared identifier.
+// DeclarationError: (1288-1289): Undeclared identifier.
+// DeclarationError: (1299-1300): Undeclared identifier.
+// DeclarationError: (1310-1311): Undeclared identifier.
+// DeclarationError: (1321-1322): Undeclared identifier.
+// DeclarationError: (1332-1333): Undeclared identifier.
+// DeclarationError: (1343-1344): Undeclared identifier.
+// DeclarationError: (1354-1355): Undeclared identifier.
+// DeclarationError: (1365-1366): Undeclared identifier.
+// DeclarationError: (1376-1377): Undeclared identifier.
+// DeclarationError: (1387-1388): Undeclared identifier.
+// DeclarationError: (1398-1399): Undeclared identifier.
+// DeclarationError: (1409-1410): Undeclared identifier.
+// DeclarationError: (1420-1421): Undeclared identifier.
+// DeclarationError: (1431-1432): Undeclared identifier.
+// DeclarationError: (1442-1443): Undeclared identifier.
+// DeclarationError: (1453-1454): Undeclared identifier.
+// DeclarationError: (1464-1465): Undeclared identifier.
+// DeclarationError: (1475-1476): Undeclared identifier.
+// DeclarationError: (1486-1487): Undeclared identifier.
+// DeclarationError: (1497-1498): Undeclared identifier.
+// DeclarationError: (1508-1509): Undeclared identifier.
+// DeclarationError: (1519-1520): Undeclared identifier.
+// DeclarationError: (1530-1531): Undeclared identifier.
+// DeclarationError: (1541-1542): Undeclared identifier.
+// DeclarationError: (1552-1553): Undeclared identifier.
+// DeclarationError: (1563-1564): Undeclared identifier.
+// DeclarationError: (1574-1575): Undeclared identifier.
+// DeclarationError: (1585-1586): Undeclared identifier.
+// DeclarationError: (1596-1597): Undeclared identifier.
+// DeclarationError: (1607-1608): Undeclared identifier.
+// DeclarationError: (1618-1619): Undeclared identifier.
+// DeclarationError: (1629-1630): Undeclared identifier.
+// DeclarationError: (1640-1641): Undeclared identifier.
+// DeclarationError: (1651-1652): Undeclared identifier.
+// DeclarationError: (1662-1663): Undeclared identifier.
+// DeclarationError: (1673-1674): Undeclared identifier.
+// DeclarationError: (1684-1685): Undeclared identifier.
+// DeclarationError: (1695-1696): Undeclared identifier.
+// DeclarationError: (1706-1707): Undeclared identifier.
+// DeclarationError: (1717-1718): Undeclared identifier.
+// DeclarationError: (1728-1729): Undeclared identifier.
+// DeclarationError: (1739-1740): Undeclared identifier.
+// DeclarationError: (1750-1751): Undeclared identifier.
+// DeclarationError: (1761-1762): Undeclared identifier.
+// DeclarationError: (1772-1773): Undeclared identifier.
+// DeclarationError: (1783-1784): Undeclared identifier.
+// DeclarationError: (1794-1795): Undeclared identifier.
+// DeclarationError: (1805-1806): Undeclared identifier.
+// DeclarationError: (1816-1817): Undeclared identifier.
+// DeclarationError: (1827-1828): Undeclared identifier.
+// DeclarationError: (1838-1839): Undeclared identifier.
+// DeclarationError: (1849-1850): Undeclared identifier.
+// DeclarationError: (1860-1861): Undeclared identifier.
+// DeclarationError: (1871-1872): Undeclared identifier.
+// DeclarationError: (1882-1883): Undeclared identifier.
+// DeclarationError: (1893-1894): Undeclared identifier.
+// DeclarationError: (1904-1905): Undeclared identifier.
+// DeclarationError: (1915-1916): Undeclared identifier.
+// DeclarationError: (1926-1927): Undeclared identifier.
+// DeclarationError: (1937-1938): Undeclared identifier.
+// DeclarationError: (1948-1949): Undeclared identifier.
+// DeclarationError: (1959-1960): Undeclared identifier.
+// DeclarationError: (1970-1971): Undeclared identifier.
+// DeclarationError: (1981-1982): Undeclared identifier.
+// DeclarationError: (1992-1993): Undeclared identifier.
+// DeclarationError: (2003-2004): Undeclared identifier.
+// DeclarationError: (2014-2015): Undeclared identifier.
+// DeclarationError: (2025-2026): Undeclared identifier.
+// DeclarationError: (2036-2037): Undeclared identifier.
+// DeclarationError: (2047-2048): Undeclared identifier.
+// DeclarationError: (2058-2059): Undeclared identifier.
+// DeclarationError: (2069-2070): Undeclared identifier.
+// DeclarationError: (2080-2081): Undeclared identifier.
+// DeclarationError: (2091-2092): Undeclared identifier.
+// DeclarationError: (2102-2103): Undeclared identifier.
+// DeclarationError: (2113-2114): Undeclared identifier.
+// DeclarationError: (2124-2125): Undeclared identifier.
+// DeclarationError: (2135-2136): Undeclared identifier.
+// DeclarationError: (2146-2147): Undeclared identifier.
+// DeclarationError: (2157-2158): Undeclared identifier.
+// DeclarationError: (2168-2169): Undeclared identifier.
+// DeclarationError: (2179-2180): Undeclared identifier.
+// DeclarationError: (2190-2191): Undeclared identifier.
+// DeclarationError: (2201-2202): Undeclared identifier.
+// DeclarationError: (2212-2213): Undeclared identifier.
+// DeclarationError: (2223-2224): Undeclared identifier.
+// DeclarationError: (2234-2235): Undeclared identifier.
+// DeclarationError: (2245-2246): Undeclared identifier.
+// DeclarationError: (2256-2257): Undeclared identifier.
+// DeclarationError: (2267-2268): Undeclared identifier.
+// DeclarationError: (2278-2279): Undeclared identifier.
+// DeclarationError: (2289-2290): Undeclared identifier.
+// DeclarationError: (2300-2301): Undeclared identifier.
+// DeclarationError: (2311-2312): Undeclared identifier.
+// DeclarationError: (2322-2323): Undeclared identifier.
+// DeclarationError: (2333-2334): Undeclared identifier.
+// DeclarationError: (2344-2345): Undeclared identifier.
+// DeclarationError: (2355-2356): Undeclared identifier.
+// DeclarationError: (2366-2367): Undeclared identifier.
+// DeclarationError: (2377-2378): Undeclared identifier.
+// DeclarationError: (2388-2389): Undeclared identifier.
+// DeclarationError: (2399-2400): Undeclared identifier.
+// DeclarationError: (2410-2411): Undeclared identifier.
+// DeclarationError: (2421-2422): Undeclared identifier.
+// DeclarationError: (2432-2433): Undeclared identifier.
+// DeclarationError: (2443-2444): Undeclared identifier.
+// DeclarationError: (2454-2455): Undeclared identifier.
+// DeclarationError: (2465-2466): Undeclared identifier.
+// DeclarationError: (2476-2477): Undeclared identifier.
+// DeclarationError: (2487-2488): Undeclared identifier.
+// DeclarationError: (2498-2499): Undeclared identifier.
+// DeclarationError: (2509-2510): Undeclared identifier.
+// DeclarationError: (2520-2521): Undeclared identifier.
+// DeclarationError: (2531-2532): Undeclared identifier.
+// DeclarationError: (2542-2543): Undeclared identifier.
+// DeclarationError: (2553-2554): Undeclared identifier.
+// DeclarationError: (2564-2565): Undeclared identifier.
+// DeclarationError: (2575-2576): Undeclared identifier.
+// DeclarationError: (2586-2587): Undeclared identifier.
+// DeclarationError: (2597-2598): Undeclared identifier.
+// DeclarationError: (2608-2609): Undeclared identifier.
+// DeclarationError: (2619-2620): Undeclared identifier.
+// DeclarationError: (2630-2631): Undeclared identifier.
+// DeclarationError: (2641-2642): Undeclared identifier.
+// DeclarationError: (2652-2653): Undeclared identifier.
+// DeclarationError: (2663-2664): Undeclared identifier.
+// DeclarationError: (2674-2675): Undeclared identifier.
+// DeclarationError: (2685-2686): Undeclared identifier.
+// DeclarationError: (2696-2697): Undeclared identifier.
+// DeclarationError: (2707-2708): Undeclared identifier.
+// DeclarationError: (2718-2719): Undeclared identifier.
+// DeclarationError: (2729-2730): Undeclared identifier.
+// DeclarationError: (2740-2741): Undeclared identifier.
+// DeclarationError: (2751-2752): Undeclared identifier.
+// DeclarationError: (2762-2763): Undeclared identifier.
+// DeclarationError: (2773-2774): Undeclared identifier.
+// DeclarationError: (2784-2785): Undeclared identifier.
+// DeclarationError: (2795-2796): Undeclared identifier.
+// DeclarationError: (2806-2807): Undeclared identifier.
+// DeclarationError: (2817-2818): Undeclared identifier.
+// DeclarationError: (2828-2829): Undeclared identifier.
+// DeclarationError: (2839-2840): Undeclared identifier.
+// Warning: There are more than 256 errors. Aborting.
diff --git a/test/libsolidity/syntaxTests/more_than_256_syntaxerrors.sol b/test/libsolidity/syntaxTests/more_than_256_syntaxerrors.sol
new file mode 100644
index 00000000..2c9b8a42
--- /dev/null
+++ b/test/libsolidity/syntaxTests/more_than_256_syntaxerrors.sol
@@ -0,0 +1,524 @@
+contract C {
+ function f() {
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ continue;
+ }
+}
+// ----
+// SyntaxError: (34-42): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (48-56): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (62-70): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (76-84): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (90-98): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (104-112): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (118-126): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (132-140): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (146-154): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (160-168): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (174-182): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (188-196): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (202-210): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (216-224): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (230-238): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (244-252): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (258-266): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (272-280): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (286-294): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (300-308): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (314-322): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (328-336): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (342-350): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (356-364): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (370-378): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (384-392): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (398-406): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (412-420): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (426-434): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (440-448): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (454-462): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (468-476): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (482-490): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (496-504): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (510-518): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (524-532): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (538-546): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (552-560): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (566-574): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (580-588): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (594-602): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (608-616): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (622-630): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (636-644): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (650-658): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (664-672): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (678-686): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (692-700): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (706-714): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (720-728): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (734-742): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (748-756): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (762-770): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (776-784): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (790-798): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (804-812): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (818-826): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (832-840): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (846-854): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (860-868): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (874-882): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (888-896): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (902-910): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (916-924): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (930-938): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (944-952): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (958-966): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (972-980): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (986-994): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1000-1008): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1014-1022): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1028-1036): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1042-1050): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1056-1064): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1070-1078): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1084-1092): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1098-1106): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1112-1120): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1126-1134): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1140-1148): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1154-1162): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1168-1176): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1182-1190): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1196-1204): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1210-1218): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1224-1232): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1238-1246): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1252-1260): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1266-1274): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1280-1288): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1294-1302): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1308-1316): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1322-1330): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1336-1344): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1350-1358): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1364-1372): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1378-1386): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1392-1400): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1406-1414): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1420-1428): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1434-1442): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1448-1456): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1462-1470): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1476-1484): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1490-1498): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1504-1512): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1518-1526): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1532-1540): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1546-1554): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1560-1568): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1574-1582): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1588-1596): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1602-1610): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1616-1624): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1630-1638): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1644-1652): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1658-1666): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1672-1680): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1686-1694): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1700-1708): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1714-1722): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1728-1736): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1742-1750): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1756-1764): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1770-1778): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1784-1792): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1798-1806): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1812-1820): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1826-1834): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1840-1848): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1854-1862): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1868-1876): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1882-1890): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1896-1904): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1910-1918): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1924-1932): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1938-1946): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1952-1960): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1966-1974): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1980-1988): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (1994-2002): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2008-2016): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2022-2030): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2036-2044): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2050-2058): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2064-2072): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2078-2086): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2092-2100): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2106-2114): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2120-2128): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2134-2142): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2148-2156): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2162-2170): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2176-2184): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2190-2198): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2204-2212): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2218-2226): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2232-2240): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2246-2254): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2260-2268): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2274-2282): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2288-2296): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2302-2310): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2316-2324): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2330-2338): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2344-2352): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2358-2366): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2372-2380): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2386-2394): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2400-2408): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2414-2422): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2428-2436): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2442-2450): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2456-2464): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2470-2478): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2484-2492): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2498-2506): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2512-2520): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2526-2534): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2540-2548): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2554-2562): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2568-2576): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2582-2590): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2596-2604): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2610-2618): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2624-2632): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2638-2646): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2652-2660): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2666-2674): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2680-2688): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2694-2702): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2708-2716): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2722-2730): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2736-2744): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2750-2758): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2764-2772): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2778-2786): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2792-2800): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2806-2814): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2820-2828): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2834-2842): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2848-2856): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2862-2870): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2876-2884): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2890-2898): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2904-2912): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2918-2926): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2932-2940): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2946-2954): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2960-2968): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2974-2982): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (2988-2996): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3002-3010): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3016-3024): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3030-3038): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3044-3052): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3058-3066): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3072-3080): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3086-3094): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3100-3108): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3114-3122): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3128-3136): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3142-3150): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3156-3164): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3170-3178): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3184-3192): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3198-3206): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3212-3220): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3226-3234): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3240-3248): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3254-3262): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3268-3276): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3282-3290): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3296-3304): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3310-3318): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3324-3332): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3338-3346): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3352-3360): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3366-3374): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3380-3388): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3394-3402): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3408-3416): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3422-3430): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3436-3444): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3450-3458): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3464-3472): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3478-3486): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3492-3500): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3506-3514): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3520-3528): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3534-3542): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3548-3556): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3562-3570): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3576-3584): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3590-3598): "continue" has to be in a "for" or "while" loop.
+// SyntaxError: (3604-3612): "continue" has to be in a "for" or "while" loop.
+// Warning: There are more than 256 errors. Aborting.
diff --git a/test/libsolidity/syntaxTests/parsing/missing_variable_name_in_declaration.sol b/test/libsolidity/syntaxTests/parsing/missing_variable_name_in_declaration.sol
new file mode 100644
index 00000000..fd3067e3
--- /dev/null
+++ b/test/libsolidity/syntaxTests/parsing/missing_variable_name_in_declaration.sol
@@ -0,0 +1,5 @@
+contract test {
+ uint256 ;
+}
+// ----
+// ParserError: (28-28): Expected identifier, got 'Semicolon'
diff --git a/test/libsolidity/syntaxTests/parsing/smoke_test.sol b/test/libsolidity/syntaxTests/parsing/smoke_test.sol
new file mode 100644
index 00000000..d328b167
--- /dev/null
+++ b/test/libsolidity/syntaxTests/parsing/smoke_test.sol
@@ -0,0 +1,4 @@
+contract test {
+ uint256 stateVariable1;
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/scoping/double_function_declaration.sol b/test/libsolidity/syntaxTests/scoping/double_function_declaration.sol
index 2841fd38..dfd67aaa 100644
--- a/test/libsolidity/syntaxTests/scoping/double_function_declaration.sol
+++ b/test/libsolidity/syntaxTests/scoping/double_function_declaration.sol
@@ -3,4 +3,4 @@ contract test {
function fun() public { }
}
// ----
-// DeclarationError: Function with same name and arguments defined twice.
+// DeclarationError: (20-45): Function with same name and arguments defined twice.
diff --git a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope.sol b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope.sol
index ea61d0f3..d90ec2d7 100644
--- a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope.sol
+++ b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope.sol
@@ -5,4 +5,4 @@ contract test {
}
}
// ----
-// DeclarationError: Identifier already declared.
+// DeclarationError: (77-83): Identifier already declared.
diff --git a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_050.sol b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_050.sol
index 22195963..06bfe7be 100644
--- a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_050.sol
+++ b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_050.sol
@@ -6,5 +6,5 @@ contract test {
}
}
// ----
-// Warning: Unused local variable.
-// Warning: Unused local variable.
+// Warning: (87-93): Unused local variable.
+// Warning: (107-113): Unused local variable.
diff --git a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation.sol b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation.sol
index 6af89c93..1a5ff2f9 100644
--- a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation.sol
+++ b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation.sol
@@ -5,4 +5,4 @@ contract test {
}
}
// ----
-// DeclarationError: Identifier already declared.
+// DeclarationError: (75-81): Identifier already declared.
diff --git a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation_050.sol b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation_050.sol
index 73cddfed..20ea0349 100644
--- a/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation_050.sol
+++ b/test/libsolidity/syntaxTests/scoping/double_variable_declaration_disjoint_scope_activation_050.sol
@@ -6,5 +6,5 @@ contract test {
}
}
// ----
-// Warning: Unused local variable.
-// Warning: Unused local variable.
+// Warning: (87-93): Unused local variable.
+// Warning: (105-111): Unused local variable.
diff --git a/test/libsolidity/syntaxTests/scoping/name_shadowing.sol b/test/libsolidity/syntaxTests/scoping/name_shadowing.sol
index d16877f9..67ada4a4 100644
--- a/test/libsolidity/syntaxTests/scoping/name_shadowing.sol
+++ b/test/libsolidity/syntaxTests/scoping/name_shadowing.sol
@@ -3,5 +3,4 @@ contract test {
function f() pure public { uint32 variable; variable = 2; }
}
// ----
-// Warning: This declaration shadows an existing declaration.
-
+// Warning: (69-84): This declaration shadows an existing declaration.
diff --git a/test/libsolidity/syntaxTests/scoping/scoping.sol b/test/libsolidity/syntaxTests/scoping/scoping.sol
index f47a3e99..34b055d9 100644
--- a/test/libsolidity/syntaxTests/scoping/scoping.sol
+++ b/test/libsolidity/syntaxTests/scoping/scoping.sol
@@ -8,4 +8,4 @@ contract test {
}
}
// ----
-// DeclarationError: Undeclared identifier.
+// DeclarationError: (123-124): Undeclared identifier.
diff --git a/test/libsolidity/syntaxTests/scoping/scoping_activation.sol b/test/libsolidity/syntaxTests/scoping/scoping_activation.sol
index 0ed74a00..7334bc49 100644
--- a/test/libsolidity/syntaxTests/scoping/scoping_activation.sol
+++ b/test/libsolidity/syntaxTests/scoping/scoping_activation.sol
@@ -6,4 +6,4 @@ contract test {
}
}
// ----
-// DeclarationError: Undeclared identifier. Did you mean "x"?
+// DeclarationError: (85-86): Undeclared identifier. Did you mean "x"?
diff --git a/test/libsolidity/syntaxTests/scoping/scoping_for3.sol b/test/libsolidity/syntaxTests/scoping/scoping_for3.sol
index 9bc7d569..1814cb47 100644
--- a/test/libsolidity/syntaxTests/scoping/scoping_for3.sol
+++ b/test/libsolidity/syntaxTests/scoping/scoping_for3.sol
@@ -8,4 +8,4 @@ contract test {
}
}
// ----
-// DeclarationError: Undeclared identifier.
+// DeclarationError: (154-155): Undeclared identifier.
diff --git a/test/libsolidity/syntaxTests/scoping/scoping_for_decl_in_body.sol b/test/libsolidity/syntaxTests/scoping/scoping_for_decl_in_body.sol
index 07503983..3e80b385 100644
--- a/test/libsolidity/syntaxTests/scoping/scoping_for_decl_in_body.sol
+++ b/test/libsolidity/syntaxTests/scoping/scoping_for_decl_in_body.sol
@@ -7,4 +7,4 @@ contract test {
}
}
// ----
-// DeclarationError: Undeclared identifier.
+// DeclarationError: (93-94): Undeclared identifier.
diff --git a/test/libsolidity/syntaxTests/scoping/scoping_self_use_050.sol b/test/libsolidity/syntaxTests/scoping/scoping_self_use_050.sol
index e942020e..ab3dcefb 100644
--- a/test/libsolidity/syntaxTests/scoping/scoping_self_use_050.sol
+++ b/test/libsolidity/syntaxTests/scoping/scoping_self_use_050.sol
@@ -5,4 +5,4 @@ contract test {
}
}
// ----
-// DeclarationError: Undeclared identifier. Did you mean "a"?
+// DeclarationError: (94-95): Undeclared identifier. Did you mean "a"?
diff --git a/test/libsolidity/syntaxTests/smoke_test.sol b/test/libsolidity/syntaxTests/smoke_test.sol
index 2d48098a..6abaff18 100644
--- a/test/libsolidity/syntaxTests/smoke_test.sol
+++ b/test/libsolidity/syntaxTests/smoke_test.sol
@@ -3,4 +3,4 @@ contract test {
function fun(uint256 arg1) public { uint256 y; y = arg1; }
}
// ----
-// Warning: Function state mutability can be restricted to pure
+// Warning: (42-100): Function state mutability can be restricted to pure
diff --git a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol
index 9f57c3a4..c98d7a57 100644
--- a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol
+++ b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol
@@ -5,7 +5,7 @@ contract C {
}
}
// ----
-// TypeError: This type cannot be encoded.
-// TypeError: This type cannot be encoded.
-// TypeError: This type cannot be encoded.
-// TypeError: This type cannot be encoded.
+// TypeError: (74-83): This type cannot be encoded.
+// TypeError: (85-86): This type cannot be encoded.
+// TypeError: (88-98): This type cannot be encoded.
+// TypeError: (100-115): This type cannot be encoded.
diff --git a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_special_types.sol b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_special_types.sol
index a7d13215..f1b5606e 100644
--- a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_special_types.sol
+++ b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_special_types.sol
@@ -6,8 +6,8 @@ contract C {
}
}
// ----
-// TypeError: This type cannot be encoded.
-// TypeError: This type cannot be encoded.
-// TypeError: This type cannot be encoded.
-// TypeError: This type cannot be encoded.
-// TypeError: This type cannot be encoded.
+// TypeError: (80-106): This type cannot be encoded.
+// TypeError: (108-113): This type cannot be encoded.
+// TypeError: (160-164): This type cannot be encoded.
+// TypeError: (166-168): This type cannot be encoded.
+// TypeError: (170-176): This type cannot be encoded.
diff --git a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs.sol b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs.sol
index 378155e9..cc354819 100644
--- a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs.sol
+++ b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_structs.sol
@@ -9,6 +9,6 @@ contract C {
}
}
// ----
-// Warning: Defining empty structs is deprecated.
-// TypeError: This type cannot be encoded.
-// TypeError: This type cannot be encoded.
+// Warning: (51-63): Defining empty structs is deprecated.
+// TypeError: (131-132): This type cannot be encoded.
+// TypeError: (134-135): This type cannot be encoded.
diff --git a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_types.sol b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_types.sol
index 6e073fd8..d10c1718 100644
--- a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_types.sol
+++ b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_types.sol
@@ -9,9 +9,9 @@ contract C {
}
}
// ----
-// Warning: Defining empty structs is deprecated.
-// TypeError: This type cannot be encoded.
-// TypeError: This type cannot be encoded.
-// TypeError: This type cannot be encoded.
-// TypeError: This type cannot be encoded.
-// TypeError: This type cannot be encoded.
+// Warning: (51-63): Defining empty structs is deprecated.
+// TypeError: (168-169): This type cannot be encoded.
+// TypeError: (171-172): This type cannot be encoded.
+// TypeError: (179-180): This type cannot be encoded.
+// TypeError: (182-186): This type cannot be encoded.
+// TypeError: (188-194): This type cannot be encoded.
diff --git a/test/libsolidity/syntaxTests/structs/recursion/multi_struct_composition.sol b/test/libsolidity/syntaxTests/structs/recursion/multi_struct_composition.sol
new file mode 100644
index 00000000..895bb6c5
--- /dev/null
+++ b/test/libsolidity/syntaxTests/structs/recursion/multi_struct_composition.sol
@@ -0,0 +1,15 @@
+pragma experimental ABIEncoderV2;
+
+contract C {
+ struct T { U u; V v; }
+
+ struct U { W w; }
+
+ struct V { W w; }
+
+ struct W { uint x; }
+
+ function f(T) public pure { }
+}
+// ----
+// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
diff --git a/test/libsolidity/syntaxTests/structs/recursion/parallel_structs.sol b/test/libsolidity/syntaxTests/structs/recursion/parallel_structs.sol
new file mode 100644
index 00000000..96362ef0
--- /dev/null
+++ b/test/libsolidity/syntaxTests/structs/recursion/parallel_structs.sol
@@ -0,0 +1,15 @@
+pragma experimental ABIEncoderV2;
+
+contract TestContract
+{
+ struct SubStruct {
+ uint256 id;
+ }
+ struct TestStruct {
+ SubStruct subStruct1;
+ SubStruct subStruct2;
+ }
+ function addTestStruct(TestStruct) public pure {}
+}
+// ----
+// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
diff --git a/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs.sol b/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs.sol
new file mode 100644
index 00000000..4966a731
--- /dev/null
+++ b/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs.sol
@@ -0,0 +1,7 @@
+contract C {
+ struct S { uint a; S[] sub; }
+ function f() public pure returns (uint, S) {
+ }
+}
+// ----
+// TypeError: (91-92): Internal or recursive type is not allowed for public or external functions.
diff --git a/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs2.sol b/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs2.sol
new file mode 100644
index 00000000..68113924
--- /dev/null
+++ b/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs2.sol
@@ -0,0 +1,7 @@
+contract C {
+ struct S { uint a; S[2][] sub; }
+ function f() public pure returns (uint, S) {
+ }
+}
+// ----
+// TypeError: (94-95): Internal or recursive type is not allowed for public or external functions.
diff --git a/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs3.sol b/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs3.sol
new file mode 100644
index 00000000..47690d9b
--- /dev/null
+++ b/test/libsolidity/syntaxTests/structs/recursion/return_recursive_structs3.sol
@@ -0,0 +1,8 @@
+contract C {
+ struct S { uint a; S[][][] sub; }
+ struct T { S s; }
+ function f() public pure returns (uint x, T t) {
+ }
+}
+// ----
+// TypeError: (119-122): Internal or recursive type is not allowed for public or external functions.
diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_directly_recursive.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_directly_recursive.sol
new file mode 100644
index 00000000..bcffe383
--- /dev/null
+++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_directly_recursive.sol
@@ -0,0 +1,8 @@
+contract Test {
+ struct MyStructName {
+ address addr;
+ MyStructName x;
+ }
+}
+// ----
+// TypeError: (20-93): Recursive struct definition.
diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive.sol
new file mode 100644
index 00000000..64dab8d0
--- /dev/null
+++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_indirectly_recursive.sol
@@ -0,0 +1,12 @@
+contract Test {
+ struct MyStructName1 {
+ address addr;
+ uint256 count;
+ MyStructName2 x;
+ }
+ struct MyStructName2 {
+ MyStructName1 x;
+ }
+}
+// ----
+// TypeError: (20-118): Recursive struct definition.
diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_not_really_recursive.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_not_really_recursive.sol
new file mode 100644
index 00000000..6ec4ee01
--- /dev/null
+++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_not_really_recursive.sol
@@ -0,0 +1,4 @@
+contract Test {
+ struct S1 { uint a; }
+ struct S2 { S1 x; S1 y; }
+}
diff --git a/test/libsolidity/syntaxTests/structs/recursion/struct_definition_recursion_via_mapping.sol b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_recursion_via_mapping.sol
new file mode 100644
index 00000000..926981b3
--- /dev/null
+++ b/test/libsolidity/syntaxTests/structs/recursion/struct_definition_recursion_via_mapping.sol
@@ -0,0 +1,7 @@
+contract Test {
+ struct MyStructName1 {
+ address addr;
+ uint256 count;
+ mapping(uint => MyStructName1) x;
+ }
+}
diff --git a/test/libsolidity/syntaxTests/visibility/interface/function_default.sol b/test/libsolidity/syntaxTests/visibility/interface/function_default.sol
index 7b9044dd..72ce3b40 100644
--- a/test/libsolidity/syntaxTests/visibility/interface/function_default.sol
+++ b/test/libsolidity/syntaxTests/visibility/interface/function_default.sol
@@ -2,5 +2,5 @@ interface I {
function f();
}
// ----
-// Warning: Functions in interfaces should be declared external.
-// Warning: No visibility specified. Defaulting to "public". In interfaces it defaults to external.
+// Warning: (15-28): Functions in interfaces should be declared external.
+// Warning: (15-28): No visibility specified. Defaulting to "public". In interfaces it defaults to external.
diff --git a/test/libsolidity/syntaxTests/visibility/interface/function_default050.sol b/test/libsolidity/syntaxTests/visibility/interface/function_default050.sol
index 127d4e92..513df26b 100644
--- a/test/libsolidity/syntaxTests/visibility/interface/function_default050.sol
+++ b/test/libsolidity/syntaxTests/visibility/interface/function_default050.sol
@@ -3,5 +3,5 @@ interface I {
function f();
}
// ----
-// SyntaxError: No visibility specified.
-// TypeError: Functions in interfaces must be declared external.
+// SyntaxError: (45-58): No visibility specified.
+// TypeError: (45-58): Functions in interfaces must be declared external.
diff --git a/test/libsolidity/syntaxTests/visibility/interface/function_internal.sol b/test/libsolidity/syntaxTests/visibility/interface/function_internal.sol
index a1cf5246..ac62e69b 100644
--- a/test/libsolidity/syntaxTests/visibility/interface/function_internal.sol
+++ b/test/libsolidity/syntaxTests/visibility/interface/function_internal.sol
@@ -2,4 +2,4 @@ interface I {
function f() internal;
}
// ----
-// TypeError: Functions in interfaces cannot be internal or private.
+// TypeError: (15-37): Functions in interfaces cannot be internal or private.
diff --git a/test/libsolidity/syntaxTests/visibility/interface/function_private.sol b/test/libsolidity/syntaxTests/visibility/interface/function_private.sol
index 887ebd4b..881e647e 100644
--- a/test/libsolidity/syntaxTests/visibility/interface/function_private.sol
+++ b/test/libsolidity/syntaxTests/visibility/interface/function_private.sol
@@ -2,4 +2,4 @@ interface I {
function f() private;
}
// ----
-// TypeError: Functions in interfaces cannot be internal or private.
+// TypeError: (15-36): Functions in interfaces cannot be internal or private.
diff --git a/test/libsolidity/syntaxTests/visibility/interface/function_public.sol b/test/libsolidity/syntaxTests/visibility/interface/function_public.sol
index 146d4f5b..891d9fdf 100644
--- a/test/libsolidity/syntaxTests/visibility/interface/function_public.sol
+++ b/test/libsolidity/syntaxTests/visibility/interface/function_public.sol
@@ -2,4 +2,4 @@ interface I {
function f() public;
}
// ----
-// Warning: Functions in interfaces should be declared external. \ No newline at end of file
+// Warning: (15-35): Functions in interfaces should be declared external.
diff --git a/test/libsolidity/syntaxTests/visibility/interface/function_public050.sol b/test/libsolidity/syntaxTests/visibility/interface/function_public050.sol
index f957f0b4..e0c04095 100644
--- a/test/libsolidity/syntaxTests/visibility/interface/function_public050.sol
+++ b/test/libsolidity/syntaxTests/visibility/interface/function_public050.sol
@@ -3,4 +3,4 @@ interface I {
function f() public;
}
// ----
-// TypeError: Functions in interfaces must be declared external. \ No newline at end of file
+// TypeError: (45-65): Functions in interfaces must be declared external.
diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp
index 5efec421..7a147bd0 100644
--- a/test/tools/isoltest.cpp
+++ b/test/tools/isoltest.cpp
@@ -55,8 +55,7 @@ public:
{
Success,
Failure,
- ParserError,
- InputOutputError
+ Exception
};
Result process();
@@ -76,7 +75,7 @@ private:
Quit
};
- Request handleResponse(bool const _parserError);
+ Request handleResponse(bool const _exception);
void printContract() const;
@@ -90,17 +89,58 @@ string SyntaxTestTool::editor;
void SyntaxTestTool::printContract() const
{
- stringstream stream(m_test->source());
- string line;
- while (getline(stream, line))
- cout << " " << line << endl;
- cout << endl;
+ if (m_formatted)
+ {
+ string const& source = m_test->source();
+ if (source.empty())
+ return;
+
+ std::vector<char const*> sourceFormatting(source.length(), formatting::RESET);
+ for (auto const& error: m_test->errorList())
+ if (error.locationStart >= 0 && error.locationEnd >= 0)
+ {
+ assert(static_cast<size_t>(error.locationStart) < source.length());
+ assert(static_cast<size_t>(error.locationEnd) < source.length());
+ bool isWarning = error.type == "Warning";
+ for (int i = error.locationStart; i < error.locationEnd; i++)
+ if (isWarning)
+ {
+ if (sourceFormatting[i] == formatting::RESET)
+ sourceFormatting[i] = formatting::ORANGE_BACKGROUND;
+ }
+ else
+ sourceFormatting[i] = formatting::RED_BACKGROUND;
+ }
+
+ cout << " " << sourceFormatting.front() << source.front();
+ for (size_t i = 1; i < source.length(); i++)
+ {
+ if (sourceFormatting[i] != sourceFormatting[i - 1])
+ cout << sourceFormatting[i];
+ if (source[i] != '\n')
+ cout << source[i];
+ else
+ {
+ cout << formatting::RESET << endl;
+ if (i + 1 < source.length())
+ cout << " " << sourceFormatting[i];
+ }
+ }
+ cout << formatting::RESET << endl;
+ }
+ else
+ {
+ stringstream stream(m_test->source());
+ string line;
+ while (getline(stream, line))
+ cout << " " << line << endl;
+ cout << endl;
+ }
}
SyntaxTestTool::Result SyntaxTestTool::process()
{
bool success;
- bool parserError = false;
std::stringstream outputMessages;
(FormattedScope(cout, m_formatted, {BOLD}) << m_name << ": ").flush();
@@ -108,21 +148,42 @@ SyntaxTestTool::Result SyntaxTestTool::process()
try
{
m_test = unique_ptr<SyntaxTest>(new SyntaxTest(m_path.string()));
+ success = m_test->run(outputMessages, " ", m_formatted);
}
- catch (std::exception const& _e)
+ catch(CompilerError const& _e)
{
- FormattedScope(cout, m_formatted, {BOLD, RED}) << "cannot read test: " << _e.what() << endl;
- return Result::InputOutputError;
+ FormattedScope(cout, m_formatted, {BOLD, RED}) <<
+ "Exception: " << SyntaxTest::errorMessage(_e) << endl;
+ return Result::Exception;
}
-
- try
+ catch(InternalCompilerError const& _e)
{
- success = m_test->run(outputMessages, " ", m_formatted);
+ FormattedScope(cout, m_formatted, {BOLD, RED}) <<
+ "InternalCompilerError: " << SyntaxTest::errorMessage(_e) << endl;
+ return Result::Exception;
+ }
+ catch(FatalError const& _e)
+ {
+ FormattedScope(cout, m_formatted, {BOLD, RED}) <<
+ "FatalError: " << SyntaxTest::errorMessage(_e) << endl;
+ return Result::Exception;
+ }
+ catch(UnimplementedFeatureError const& _e)
+ {
+ FormattedScope(cout, m_formatted, {BOLD, RED}) <<
+ "UnimplementedFeatureError: " << SyntaxTest::errorMessage(_e) << endl;
+ return Result::Exception;
+ }
+ catch (std::exception const& _e)
+ {
+ FormattedScope(cout, m_formatted, {BOLD, RED}) << "Exception: " << _e.what() << endl;
+ return Result::Exception;
}
- catch (...)
+ catch(...)
{
- success = false;
- parserError = true;
+ FormattedScope(cout, m_formatted, {BOLD, RED}) <<
+ "Unknown Exception" << endl;
+ return Result::Exception;
}
if (success)
@@ -137,25 +198,14 @@ SyntaxTestTool::Result SyntaxTestTool::process()
FormattedScope(cout, m_formatted, {BOLD, CYAN}) << " Contract:" << endl;
printContract();
- if (parserError)
- {
- cout << " ";
- FormattedScope(cout, m_formatted, {INVERSE, RED}) << "Parsing failed:" << endl;
- m_test->printErrorList(cout, m_test->compilerErrors(), " ", true, true, m_formatted);
- cout << endl;
- return Result::ParserError;
- }
- else
- {
- cout << outputMessages.str() << endl;
- return Result::Failure;
- }
+ cout << outputMessages.str() << endl;
+ return Result::Failure;
}
}
-SyntaxTestTool::Request SyntaxTestTool::handleResponse(bool const _parserError)
+SyntaxTestTool::Request SyntaxTestTool::handleResponse(bool const _exception)
{
- if (_parserError)
+ if (_exception)
cout << "(e)dit/(s)kip/(q)uit? ";
else
cout << "(e)dit/(u)pdate expectations/(s)kip/(q)uit? ";
@@ -169,7 +219,7 @@ SyntaxTestTool::Request SyntaxTestTool::handleResponse(bool const _parserError)
cout << endl;
return Request::Skip;
case 'u':
- if (_parserError)
+ if (_exception)
break;
else
{
@@ -178,7 +228,7 @@ SyntaxTestTool::Request SyntaxTestTool::handleResponse(bool const _parserError)
file << m_test->source();
file << "// ----" << endl;
if (!m_test->errorList().empty())
- m_test->printErrorList(file, m_test->errorList(), "// ", false, false, false);
+ m_test->printErrorList(file, m_test->errorList(), "// ", false);
return Request::Rerun;
}
case 'e':
@@ -231,8 +281,8 @@ SyntaxTestStats SyntaxTestTool::processPath(
switch(result)
{
case Result::Failure:
- case Result::ParserError:
- switch(testTool.handleResponse(result == Result::ParserError))
+ case Result::Exception:
+ switch(testTool.handleResponse(result == Result::Exception))
{
case Request::Quit:
return { successCount, runCount };
@@ -249,10 +299,6 @@ SyntaxTestStats SyntaxTestTool::processPath(
paths.pop();
++successCount;
break;
- default:
- // non-recoverable error; continue with next test case
- paths.pop();
- break;
}
}
}