diff options
93 files changed, 846 insertions, 1000 deletions
diff --git a/Changelog.md b/Changelog.md index 9bed7e9c..c31aced2 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,9 +1,26 @@ ### 0.5.0 (unreleased) +Breaking Changes: + * Disallow conversions between bytesX and uintY of different size. + * Commandline interface: Require ``-`` if standard input is used as source. + * General: ``continue`` in a ``do...while`` loop jumps to the condition (it used to jump to the loop body). Warning: this may silently change the semantics of existing code. + * Type Checker: Disallow arithmetic operations for Boolean variables. + +Features: + +Bugfixes: + + + +Features: + + +Bugfixes: ### 0.4.24 (2018-05-16) + Language Features: * Code Generator: Use native shift instructions on target Constantinople. * General: Allow multiple variables to be declared as part of a tuple assignment, e.g. ``(uint a, uint b) = ...``. @@ -129,6 +129,7 @@ jobs: command: | apt-get -qq update apt-get -qy install cmake libboost-regex-dev libboost-filesystem-dev libboost-test-dev libboost-system-dev libboost-program-options-dev libz3-dev + ./scripts/install_obsolete_jsoncpp_1_7_4.sh - run: *setup_prerelease_commit_hash - run: *run_build - store_artifacts: *solc_artifact @@ -150,6 +151,8 @@ jobs: brew install z3 brew install boost brew install cmake + brew install wget + ./scripts/install_obsolete_jsoncpp_1_7_4.sh - run: *setup_prerelease_commit_hash - run: *run_build - store_artifacts: *solc_artifact @@ -204,7 +207,7 @@ jobs: name: Install build dependencies command: | apt-get -qq update - apt-get -qy install python-sphinx + apt-get -qy install python-sphinx python-pip - run: *setup_prerelease_commit_hash - run: name: Build documentation diff --git a/cmake/scripts/buildinfo.cmake b/cmake/scripts/buildinfo.cmake index efbfb8fb..9147a1b4 100644 --- a/cmake/scripts/buildinfo.cmake +++ b/cmake/scripts/buildinfo.cmake @@ -19,7 +19,7 @@ if (NOT ETH_BUILD_PLATFORM) set(ETH_BUILD_PLATFORM "unknown") endif() -# Logic here: If prereleases.txt exists but is empty, it is a non-pre release. +# Logic here: If prerelease.txt exists but is empty, it is a non-pre release. # If it does not exist, create our own prerelease string if (EXISTS ${ETH_SOURCE_DIR}/prerelease.txt) file(READ ${ETH_SOURCE_DIR}/prerelease.txt SOL_VERSION_PRERELEASE) diff --git a/docs/_templates/layout.html b/docs/_templates/layout.html new file mode 100644 index 00000000..c5886276 --- /dev/null +++ b/docs/_templates/layout.html @@ -0,0 +1,6 @@ +{% extends "!layout.html" %} + + {% block menu %} + <a href="genindex.html">Keyword Index</a> + {{ super() }} + {% endblock %} diff --git a/docs/assembly.rst b/docs/assembly.rst index 443cb7da..f7b721ab 100644 --- a/docs/assembly.rst +++ b/docs/assembly.rst @@ -115,7 +115,7 @@ you really know what you are doing. // Iterate until the bound is not met. for - { let end := add(data, len) } + { let end := add(data, mul(len, 0x20)) } lt(data, end) { data := add(data, 0x20) } { diff --git a/docs/conf.py b/docs/conf.py index 7e107f2a..fdb67367 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -24,7 +24,7 @@ import re def setup(sphinx): thisdir = os.path.dirname(os.path.realpath(__file__)) sys.path.insert(0, thisdir + '/utils') - from SolidityLexer import SolidityLexer + from pygments_lexer_solidity import SolidityLexer sphinx.add_lexer('Solidity', SolidityLexer()) # -- General configuration ------------------------------------------------ @@ -112,7 +112,7 @@ highlight_language = 'Solidity' # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -html_theme = 'default' +html_theme = 'sphinx_rtd_theme' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the diff --git a/docs/contracts.rst b/docs/contracts.rst index b73fe2ca..7f1899fa 100644 --- a/docs/contracts.rst +++ b/docs/contracts.rst @@ -526,9 +526,14 @@ In addition to the list of state modifying statements explained above, the follo It is not possible to prevent functions from reading the state at the level of the EVM, it is only possible to prevent them from writing to the state (i.e. only ``view`` can be enforced at the EVM level, ``pure`` can not). + It is a non-circumventable runtime checks done by the EVM. .. warning:: Before version 0.4.17 the compiler didn't enforce that ``pure`` is not reading the state. + It is a compile-time type check, which can be circumvented doing invalid explicit conversions + between contract types, because the compiler can verify that the type of the contract does + not do state-changing operations, but it cannot check that the contract that will be called + at runtime is actually of that type. .. index:: ! fallback function, function;fallback @@ -802,7 +807,7 @@ as topics. The event call above can be performed in the same way as log3( bytes32(msg.value), bytes32(0x50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb20), - bytes32(msg.sender), + bytes32(uint256(msg.sender)), _id ); } diff --git a/docs/introduction-to-smart-contracts.rst b/docs/introduction-to-smart-contracts.rst index d1789c44..71f9bd8e 100644 --- a/docs/introduction-to-smart-contracts.rst +++ b/docs/introduction-to-smart-contracts.rst @@ -33,7 +33,7 @@ Storage The first line simply tells that the source code is written for Solidity version 0.4.0 or anything newer that does not break functionality (up to, but not including, version 0.5.0). This is to ensure that the -contract does not suddenly behave differently with a new compiler version. The keyword ``pragma`` is called that way because, in general, +contract does not suddenly behave differently with a new compiler version. The keyword ``pragma`` is called that because, in general, pragmas are instructions for the compiler about how to treat the source code (e.g. `pragma once <https://en.wikipedia.org/wiki/Pragma_once>`_). @@ -62,7 +62,7 @@ so that only you can alter the number. the ASCII character set. It is possible to store UTF-8 encoded data in string variables. .. warning:: - Be careful with using Unicode text as similarly looking (or even identical) characters can + Be careful with using Unicode text, as similar looking (or even identical) characters can have different code points and as such will be encoded as a different byte array. .. index:: ! subcurrency @@ -75,7 +75,7 @@ cryptocurrency. It is possible to generate coins out of thin air, but only the person that created the contract will be able to do that (it is trivial to implement a different issuance scheme). Furthermore, anyone can send coins to each other without any need for -registering with username and password - all you need is an Ethereum keypair. +registering with username and password — all you need is an Ethereum keypair. :: @@ -88,7 +88,7 @@ registering with username and password - all you need is an Ethereum keypair. address public minter; mapping (address => uint) public balances; - // Events allow light clients to react on + // Events allow light clients to react to // changes efficiently. event Sent(address from, address to, uint amount); diff --git a/docs/layout-of-source-files.rst b/docs/layout-of-source-files.rst index f9d197b7..81faf816 100644 --- a/docs/layout-of-source-files.rst +++ b/docs/layout-of-source-files.rst @@ -198,7 +198,7 @@ for the two input parameters and two returned values. pragma solidity ^0.4.0; /** @title Shape calculator. */ - contract shapeCalculator { + contract ShapeCalculator { /** @dev Calculates a rectangle's surface and perimeter. * @param w Width of the rectangle. * @param h Height of the rectangle. diff --git a/docs/requirements.txt b/docs/requirements.txt index 0607b1ef..5fba631c 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1 +1,2 @@ sphinx_rtd_theme>=0.3.1 +pygments-lexer-solidity>=0.3.1 diff --git a/docs/types.rst b/docs/types.rst index 5c20dc67..3f799c32 100644 --- a/docs/types.rst +++ b/docs/types.rst @@ -762,7 +762,7 @@ Members // Create a dynamic byte array: bytes memory b = new bytes(200); for (uint i = 0; i < b.length; i++) - b[i] = byte(i); + b[i] = byte(uint8(i)); return b; } } @@ -975,6 +975,15 @@ cut off:: uint32 a = 0x12345678; uint16 b = uint16(a); // b will be 0x5678 now +Since 0.5.0 explicit conversions between integers and fixed-size byte arrays +are only allowed, if both have the same size. To convert between integers and +fixed-size byte arrays of different size, they first have to be explicitly +converted to a matching size. This makes alignment and padding explicit:: + + uint16 x = 0xffff; + bytes32(uint256(x)); // pad on the left + bytes32(bytes2(x)); // pad on the right + .. index:: ! type;deduction, ! var .. _type-deduction: diff --git a/docs/utils/SolidityLexer.py b/docs/utils/SolidityLexer.py deleted file mode 100644 index 50f51cf4..00000000 --- a/docs/utils/SolidityLexer.py +++ /dev/null @@ -1,82 +0,0 @@ -# -*- coding: utf-8 -*- - -import re -import copy - -from pygments.lexer import RegexLexer, ExtendedRegexLexer, bygroups, using, \ - include, this -from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ - Number, Other, Punctuation, Literal - -__all__ = ['SolidityLexer'] - -class SolidityLexer(RegexLexer): - name = "Solidity" - aliases = ['sol', 'solidity'] - filenames = ['*.sol'] - mimetypes = [] - flags = re.DOTALL - tokens = { - 'commentsandwhitespace': [ - (r'\s+', Text), - (r'<!--', Comment), - (r'///', Comment.Special, 'docstringsingle'), - (r'//.*?\n', Comment.Single), - (r'/\*\*', Comment.Special, 'docstringmulti'), - (r'/\*.*?\*/', Comment.Multiline) - ], - 'natspec': [ - (r'@author|@dev|@notice|@return|@param|@title', Keyword), - (r'.[^@*\n]*?', Comment.Special) - ], - 'docstringsingle': [ - (r'\n', Comment.Special, '#pop'), - include('natspec') - ], - 'docstringmulti': [ - (r'\*/', Comment.Special, '#pop'), - include('natspec') - ], - 'slashstartsregex': [ - include('commentsandwhitespace'), - (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' - r'([gim]+\b|\B)', String.Regex, '#pop'), - (r'(?=/)', Text, ('#pop', 'badregex')), - (r'', Text, '#pop') - ], - 'badregex': [ - (r'\n', Text, '#pop') - ], - 'root': [ - (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), - include('commentsandwhitespace'), - (r'\+\+|--|\*\*|~|&&|\?|:|\|\||\\(?=\n)|' - r'(<<|>>>?|==?|!=?|[-<>+*%&\|\^/])=?', Operator, 'slashstartsregex'), - (r'[{(\[;,]', Punctuation, 'slashstartsregex'), - (r'[})\].]', Punctuation), - (r'(anonymous|as|assembly|break|constant|continue|do|delete|else|external|for|hex|if|' - r'indexed|internal|import|is|mapping|memory|new|payable|public|pragma|' - r'private|pure|return|returns|storage|super|this|throw|using|view|while)\b', Keyword, 'slashstartsregex'), - (r'(var|function|event|modifier|struct|enum|contract|library|interface)\b', Keyword.Declaration, 'slashstartsregex'), - (r'(bytes|string|address|uint|int|bool|byte|' + - '|'.join( - ['uint%d' % (i + 8) for i in range(0, 256, 8)] + - ['int%d' % (i + 8) for i in range(0, 256, 8)] + - ['bytes%d' % (i + 1) for i in range(0, 32)] + - ['ufixed%dx%d' % ((i), (j + 8)) for i in range(0, 256, 8) for j in range(0, 256 - i, 8)] + - ['fixed%dx%d' % ((i), (j + 8)) for i in range(0, 256, 8) for j in range(0, 256 - i, 8)] - ) + r')\b', Keyword.Type, 'slashstartsregex'), - (r'(wei|szabo|finney|ether|seconds|minutes|hours|days|weeks|years)\b', Keyword.Type, 'slashstartsregex'), - (r'(abstract|after|case|catch|default|final|in|inline|let|match|' - r'null|of|relocatable|static|switch|try|type|typeof)\b', Keyword.Reserved), - (r'(true|false)\b', Keyword.Constant), - (r'(block|msg|tx|now|suicide|selfdestruct|addmod|mulmod|sha3|keccak256|log[0-4]|' - r'sha256|ecrecover|ripemd160|assert|revert|require)', Name.Builtin), - (r'[$a-zA-Z_][a-zA-Z0-9_]*', Name.Other), - (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?', Number.Float), - (r'0x[0-9a-fA-F]+', Number.Hex), - (r'[0-9]+([eE][0-9]+)?', Number.Integer), - (r'"(\\\\|\\"|[^"])*"', String.Double), - (r"'(\\\\|\\'|[^'])*'", String.Single), - ] - } diff --git a/libsolidity/analysis/ControlFlowBuilder.cpp b/libsolidity/analysis/ControlFlowBuilder.cpp index 35d7687c..5bd39da3 100644 --- a/libsolidity/analysis/ControlFlowBuilder.cpp +++ b/libsolidity/analysis/ControlFlowBuilder.cpp @@ -159,15 +159,14 @@ bool ControlFlowBuilder::visit(WhileStatement const& _whileStatement) { auto afterWhile = newLabel(); auto whileBody = createLabelHere(); + auto condition = newLabel(); { - // Note that "continue" in this case currently indeed jumps to whileBody - // and not to the condition. This is inconsistent with JavaScript and C and - // therefore a bug. This will be fixed in the future (planned for 0.5.0) - // and the Control Flow Graph will have to be adjusted accordingly. - BreakContinueScope scope(*this, afterWhile, whileBody); + BreakContinueScope scope(*this, afterWhile, condition); appendControlFlow(_whileStatement.body()); } + + placeAndConnectLabel(condition); appendControlFlow(_whileStatement.condition()); connect(m_currentNode, whileBody); diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 268bcbe4..59668e1d 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -490,7 +490,7 @@ bool IntegerType::isExplicitlyConvertibleTo(Type const& _convertTo) const return _convertTo.category() == category() || _convertTo.category() == Category::Contract || _convertTo.category() == Category::Enum || - _convertTo.category() == Category::FixedBytes || + (_convertTo.category() == Category::FixedBytes && numBits() == dynamic_cast<FixedBytesType const&>(_convertTo).numBytes() * 8) || _convertTo.category() == Category::FixedPoint; } @@ -898,7 +898,10 @@ bool RationalNumberType::isImplicitlyConvertibleTo(Type const& _convertTo) const bool RationalNumberType::isExplicitlyConvertibleTo(Type const& _convertTo) const { TypePointer mobType = mobileType(); - return mobType && mobType->isExplicitlyConvertibleTo(_convertTo); + return + (mobType && mobType->isExplicitlyConvertibleTo(_convertTo)) || + (!isFractional() && _convertTo.category() == Category::FixedBytes) + ; } TypePointer RationalNumberType::unaryOperatorResult(Token::Value _operator) const @@ -1295,7 +1298,7 @@ bool FixedBytesType::isImplicitlyConvertibleTo(Type const& _convertTo) const bool FixedBytesType::isExplicitlyConvertibleTo(Type const& _convertTo) const { - return _convertTo.category() == Category::Integer || + return (_convertTo.category() == Category::Integer && numBytes() * 8 == dynamic_cast<IntegerType const&>(_convertTo).numBits()) || _convertTo.category() == Category::FixedPoint || _convertTo.category() == category(); } @@ -1372,7 +1375,7 @@ TypePointer BoolType::binaryOperatorResult(Token::Value _operator, TypePointer c { if (category() != _other->category()) return TypePointer(); - if (Token::isCompareOp(_operator) || _operator == Token::And || _operator == Token::Or) + if (_operator == Token::Equal || _operator == Token::NotEqual || _operator == Token::And || _operator == Token::Or) return _other; else return TypePointer(); diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp index 0889ac7c..f195b416 100644 --- a/libsolidity/codegen/ContractCompiler.cpp +++ b/libsolidity/codegen/ContractCompiler.cpp @@ -666,32 +666,36 @@ bool ContractCompiler::visit(WhileStatement const& _whileStatement) { StackHeightChecker checker(m_context); CompilerContext::LocationSetter locationSetter(m_context, _whileStatement); + eth::AssemblyItem loopStart = m_context.newTag(); eth::AssemblyItem loopEnd = m_context.newTag(); - m_continueTags.push_back(loopStart); m_breakTags.push_back(loopEnd); m_context << loopStart; - // While loops have the condition prepended - if (!_whileStatement.isDoWhile()) + if (_whileStatement.isDoWhile()) { - compileExpression(_whileStatement.condition()); - m_context << Instruction::ISZERO; - m_context.appendConditionalJumpTo(loopEnd); - } + eth::AssemblyItem condition = m_context.newTag(); + m_continueTags.push_back(condition); - _whileStatement.body().accept(*this); + _whileStatement.body().accept(*this); - // Do-while loops have the condition appended - if (_whileStatement.isDoWhile()) + m_context << condition; + compileExpression(_whileStatement.condition()); + m_context << Instruction::ISZERO << Instruction::ISZERO; + m_context.appendConditionalJumpTo(loopStart); + } + else { + m_continueTags.push_back(loopStart); compileExpression(_whileStatement.condition()); m_context << Instruction::ISZERO; m_context.appendConditionalJumpTo(loopEnd); - } - m_context.appendJumpTo(loopStart); + _whileStatement.body().accept(*this); + + m_context.appendJumpTo(loopStart); + } m_context << loopEnd; m_continueTags.pop_back(); diff --git a/libsolidity/formal/SMTChecker.cpp b/libsolidity/formal/SMTChecker.cpp index 425c5c1e..8639317b 100644 --- a/libsolidity/formal/SMTChecker.cpp +++ b/libsolidity/formal/SMTChecker.cpp @@ -485,11 +485,7 @@ void SMTChecker::compareOperation(BinaryOperation const& _op) solUnimplementedAssert(SSAVariable::isBool(_op.annotation().commonType->category()), "Operation not yet supported"); value = make_shared<smt::Expression>( op == Token::Equal ? (left == right) : - op == Token::NotEqual ? (left != right) : - op == Token::LessThan ? (!left && right) : - op == Token::LessThanOrEqual ? (!left || right) : - op == Token::GreaterThan ? (left && !right) : - /*op == Token::GreaterThanOrEqual*/ (left || !right) + /*op == Token::NotEqual*/ (left != right) ); } // TODO: check that other values for op are not possible. diff --git a/scripts/docs.sh b/scripts/docs.sh index 42400bc7..2c08a82b 100755 --- a/scripts/docs.sh +++ b/scripts/docs.sh @@ -28,5 +28,6 @@ set -e cd docs +pip install -r requirements.txt sphinx-build -nW -b html -d _build/doctrees . _build/html cd .. diff --git a/scripts/install_deps.sh b/scripts/install_deps.sh index 1843b064..ace6580a 100755 --- a/scripts/install_deps.sh +++ b/scripts/install_deps.sh @@ -159,7 +159,7 @@ case $(uname -s) in # See https://pkgs.alpinelinux.org/ apk update - apk add boost-dev build-base cmake + apk add boost-dev build-base cmake git ;; diff --git a/scripts/install_obsolete_jsoncpp_1_7_4.sh b/scripts/install_obsolete_jsoncpp_1_7_4.sh new file mode 100755 index 00000000..0ae7b34c --- /dev/null +++ b/scripts/install_obsolete_jsoncpp_1_7_4.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env sh +set -e + +TEMPDIR=$(mktemp -d) +( + cd $TEMPDIR + wget https://github.com/open-source-parsers/jsoncpp/archive/1.7.4.tar.gz + tar xvzf "1.7.4.tar.gz" + cd "jsoncpp-1.7.4" + mkdir -p build + cd build + cmake -DARCHIVE_INSTALL_DIR=. -G "Unix Makefiles" .. + make + make install +) +rm -rf $TEMPDIR diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 1f04c68a..89ac8806 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -404,9 +404,7 @@ bool CommandLineInterface::readInputFilesAndConfigureRemappings() { bool ignoreMissing = m_args.count(g_argIgnoreMissingFiles); bool addStdin = false; - if (!m_args.count(g_argInputFile)) - addStdin = true; - else + if (m_args.count(g_argInputFile)) for (string path: m_args[g_argInputFile].as<vector<string>>()) { auto eq = find(path.begin(), path.end(), '='); @@ -450,6 +448,11 @@ bool CommandLineInterface::readInputFilesAndConfigureRemappings() } if (addStdin) m_sourceCodes[g_stdinFileName] = dev::readStandardInput(); + if (m_sourceCodes.size() == 0) + { + cerr << "No input files given. If you wish to use the standard input please specify \"-\" explicity." << endl; + return false; + } return true; } diff --git a/test/cmdlineTests.sh b/test/cmdlineTests.sh index 1137c7b0..74b6a5a7 100755 --- a/test/cmdlineTests.sh +++ b/test/cmdlineTests.sh @@ -139,25 +139,55 @@ rm -rf "$TMPDIR" echo "Done." printTask "Testing library checksum..." -echo '' | "$SOLC" --link --libraries a:0x90f20564390eAe531E810af625A22f51385Cd222 -! echo '' | "$SOLC" --link --libraries a:0x80f20564390eAe531E810af625A22f51385Cd222 2>/dev/null +echo '' | "$SOLC" - --link --libraries a:0x90f20564390eAe531E810af625A22f51385Cd222 >/dev/null +! echo '' | "$SOLC" - --link --libraries a:0x80f20564390eAe531E810af625A22f51385Cd222 &>/dev/null printTask "Testing long library names..." -echo '' | "$SOLC" --link --libraries aveeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerylonglibraryname:0x90f20564390eAe531E810af625A22f51385Cd222 +echo '' | "$SOLC" - --link --libraries aveeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerylonglibraryname:0x90f20564390eAe531E810af625A22f51385Cd222 >/dev/null -printTask "Testing overwriting files" +printTask "Testing overwriting files..." TMPDIR=$(mktemp -d) ( set -e # First time it works - echo 'contract C {} ' | "$SOLC" --bin -o "$TMPDIR/non-existing-stuff-to-create" 2>/dev/null + echo 'contract C {} ' | "$SOLC" - --bin -o "$TMPDIR/non-existing-stuff-to-create" 2>/dev/null # Second time it fails - ! echo 'contract C {} ' | "$SOLC" --bin -o "$TMPDIR/non-existing-stuff-to-create" 2>/dev/null + ! echo 'contract C {} ' | "$SOLC" - --bin -o "$TMPDIR/non-existing-stuff-to-create" 2>/dev/null # Unless we force - echo 'contract C {} ' | "$SOLC" --overwrite --bin -o "$TMPDIR/non-existing-stuff-to-create" 2>/dev/null + echo 'contract C {} ' | "$SOLC" - --overwrite --bin -o "$TMPDIR/non-existing-stuff-to-create" 2>/dev/null ) rm -rf "$TMPDIR" +printTask "Testing assemble, yul, strict-assembly..." +echo '{}' | "$SOLC" - --assemble &>/dev/null +echo '{}' | "$SOLC" - --julia &>/dev/null +echo '{}' | "$SOLC" - --strict-assembly &>/dev/null + +printTask "Testing standard input..." +TMPDIR=$(mktemp -d) +( + set +e + output=$("$SOLC" --bin 2>&1) + result=$? + set -e + + # This should fail + if [[ !("$output" =~ "No input files given") || ($result == 0) ]] ; then + printError "Incorrect response to empty input arg list: $STDERR" + exit 1 + fi + + set +e + output=$(echo 'contract C {} ' | "$SOLC" - --bin 2>/dev/null | grep -q "<stdin>:C") + result=$? + set -e + + # The contract should be compiled + if [[ "$result" != 0 ]] ; then + exit 1 + fi +) + printTask "Testing soljson via the fuzzer..." TMPDIR=$(mktemp -d) ( diff --git a/test/compilationTests/milestonetracker/RLP.sol b/test/compilationTests/milestonetracker/RLP.sol index 5bb27bb2..1b8cd1cb 100644 --- a/test/compilationTests/milestonetracker/RLP.sol +++ b/test/compilationTests/milestonetracker/RLP.sol @@ -263,7 +263,7 @@ library RLP { var (rStartPos, len) = _decode(self); if (len != 1) throw; - uint temp; + uint8 temp; assembly { temp := byte(0, mload(rStartPos)) } diff --git a/test/libsolidity/ABIDecoderTests.cpp b/test/libsolidity/ABIDecoderTests.cpp index beb7b5af..b3ebb7a5 100644 --- a/test/libsolidity/ABIDecoderTests.cpp +++ b/test/libsolidity/ABIDecoderTests.cpp @@ -579,7 +579,7 @@ BOOST_AUTO_TEST_CASE(struct_simple) a = s.a; b = s.b; c = s.c; - d = uint(s.d); + d = uint16(s.d); } } )"; diff --git a/test/libsolidity/SMTChecker.cpp b/test/libsolidity/SMTChecker.cpp index 71fdb906..ec23f452 100644 --- a/test/libsolidity/SMTChecker.cpp +++ b/test/libsolidity/SMTChecker.cpp @@ -388,35 +388,6 @@ BOOST_AUTO_TEST_CASE(bool_simple) } )"; CHECK_SUCCESS_NO_WARNINGS(text); - text = R"( - contract C { - function f(bool x) public pure { - bool y; - assert(x <= y); - } - } - )"; - CHECK_WARNING(text, "Assertion violation happens here"); - text = R"( - contract C { - function f(bool x) public pure { - bool y; - assert(x >= y); - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); - text = R"( - contract C { - function f(bool x) public pure { - require(x); - bool y; - assert(x > y); - assert(y < x); - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); } BOOST_AUTO_TEST_CASE(bool_int_mixed) diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index d00b174c..40962294 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -483,6 +483,27 @@ BOOST_AUTO_TEST_CASE(do_while_loop) testContractAgainstCppOnRange("f(uint256)", do_while_loop_cpp, 0, 5); } +BOOST_AUTO_TEST_CASE(do_while_loop_continue) +{ + char const* sourceCode = R"( + contract test { + function f() public pure returns(uint r) { + uint i = 0; + do + { + if (i > 0) return 0; + i++; + continue; + } while (false); + return 42; + } + } + )"; + compileAndRun(sourceCode); + + ABI_CHECK(callContractFunction("f()"), encodeArgs(42)); +} + BOOST_AUTO_TEST_CASE(nested_loops) { // tests that break and continue statements in nested loops jump to the correct place @@ -1668,7 +1689,7 @@ BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_smaller_size) char const* sourceCode = R"( contract Test { function bytesToUint(bytes4 s) returns (uint16 h) { - return uint16(s); + return uint16(uint32(s)); } } )"; @@ -1684,7 +1705,7 @@ BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_greater_size) char const* sourceCode = R"( contract Test { function bytesToUint(bytes4 s) returns (uint64 h) { - return uint64(s); + return uint64(uint32(s)); } } )"; @@ -1731,7 +1752,7 @@ BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_smaller_size) char const* sourceCode = R"( contract Test { function uintToBytes(uint32 h) returns (bytes2 s) { - return bytes2(h); + return bytes2(uint16(h)); } } )"; @@ -1747,7 +1768,7 @@ BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_greater_size) char const* sourceCode = R"( contract Test { function UintToBytes(uint16 h) returns (bytes8 s) { - return bytes8(h); + return bytes8(uint64(h)); } } )"; @@ -3138,7 +3159,7 @@ BOOST_AUTO_TEST_CASE(event) function deposit(bytes32 _id, bool _manually) payable { if (_manually) { bytes32 s = 0x19dacbf83c5de6658e14cbf7bcae5c15eca2eedecf1c66fbca928e4d351bea0f; - log3(bytes32(msg.value), s, bytes32(msg.sender), _id); + log3(bytes32(msg.value), s, bytes32(uint256(msg.sender)), _id); } else { Deposit(msg.sender, _id, msg.value); } @@ -3535,7 +3556,7 @@ BOOST_AUTO_TEST_CASE(event_indexed_string) event E(string indexed r, uint[4] indexed t); function deposit() { bytes(x).length = 90; - for (uint i = 0; i < 90; i++) + for (uint8 i = 0; i < 90; i++) bytes(x)[i] = byte(i); y[0] = 4; y[1] = 5; @@ -4767,7 +4788,7 @@ BOOST_AUTO_TEST_CASE(array_copy_different_packing) function test() returns (bytes10 a, bytes10 b, bytes10 c, bytes10 d, bytes10 e) { data1.length = 9; for (uint i = 0; i < data1.length; ++i) - data1[i] = bytes8(i); + data1[i] = bytes8(uint64(i)); data2 = data1; a = data2[1]; b = data2[2]; @@ -4795,7 +4816,7 @@ BOOST_AUTO_TEST_CASE(array_copy_target_simple) bytes17[10] data2; // 1 per slot, no offset counter function test() returns (bytes17 a, bytes17 b, bytes17 c, bytes17 d, bytes17 e) { for (uint i = 0; i < data1.length; ++i) - data1[i] = bytes8(i); + data1[i] = bytes8(uint64(i)); data2[8] = data2[9] = 2; data2 = data1; a = data2[1]; @@ -4827,14 +4848,14 @@ BOOST_AUTO_TEST_CASE(array_copy_target_leftover) uint i; for (i = 0; i < data2.length; ++i) data2[i] = 0xffff; - check = uint(data2[31]) * 0x10000 | uint(data2[14]); + check = uint(uint16(data2[31])) * 0x10000 | uint(uint16(data2[14])); for (i = 0; i < data1.length; ++i) data1[i] = byte(uint8(1 + i)); data2 = data1; for (i = 0; i < 16; ++i) - res1 |= uint(data2[i]) * 0x10000**i; + res1 |= uint(uint16(data2[i])) * 0x10000**i; for (i = 0; i < 16; ++i) - res2 |= uint(data2[16 + i]) * 0x10000**i; + res2 |= uint(uint16(data2[16 + i])) * 0x10000**i; } } )"; @@ -4860,7 +4881,7 @@ BOOST_AUTO_TEST_CASE(array_copy_target_leftover2) data1[2] = 3; data1[3] = 4; for (uint i = 0; i < data2.length; ++i) - data2[i] = bytes10(0xffff00 | (1 + i)); + data2[i] = bytes10(uint80(0xffff00 | (1 + i))); data2 = data1; r1 = data2[3]; r2 = data2[4]; @@ -5074,7 +5095,7 @@ BOOST_AUTO_TEST_CASE(byte_array_push_transition) contract c { bytes data; function test() returns (uint) { - for (uint i = 1; i < 40; i++) + for (uint8 i = 1; i < 40; i++) { data.push(byte(i)); if (data.length != i) return 0x1000 + i; @@ -5120,11 +5141,11 @@ BOOST_AUTO_TEST_CASE(bytes_index_access) contract c { bytes data; function direct(bytes arg, uint index) external returns (uint) { - return uint(arg[index]); + return uint(uint8(arg[index])); } function storageCopyRead(bytes arg, uint index) external returns (uint) { data = arg; - return uint(data[index]); + return uint(uint8(data[index])); } function storageWrite() external returns (uint) { data.length = 35; @@ -5135,7 +5156,7 @@ BOOST_AUTO_TEST_CASE(bytes_index_access) data[31] |= 8; data[30] = 1; data[32] = 3; - return uint(data[30]) * 0x100 | uint(data[31]) * 0x10 | uint(data[32]); + return uint(uint8(data[30])) * 0x100 | uint(uint8(data[31])) * 0x10 | uint(uint8(data[32])); } } )"; @@ -5158,7 +5179,7 @@ BOOST_AUTO_TEST_CASE(bytes_delete_element) function test1() external returns (bool) { data.length = 100; for (uint i = 0; i < data.length; i++) - data[i] = byte(i); + data[i] = byte(uint8(i)); delete data[94]; delete data[96]; delete data[98]; @@ -7517,7 +7538,7 @@ BOOST_AUTO_TEST_CASE(short_strings) if (data1[0] != "1") return 10; if (data1[4] != "4") return 11; for (uint i = 0; i < data1.length; i ++) - data1[i] = byte(i * 3); + data1[i] = byte(uint8(i * 3)); if (data1[4] != 4 * 3) return 12; if (data1[67] != 67 * 3) return 13; // change length: long -> short @@ -8333,7 +8354,7 @@ BOOST_AUTO_TEST_CASE(fixed_bytes_index_access) function g(bytes32 x) returns (uint) { data = [x[0], x[1], x[2]]; data[0] = "12345"; - return uint(data[0][4]); + return uint(uint8(data[0][4])); } } )"; @@ -8391,7 +8412,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_memory_access) function test() returns (bytes) { bytes memory x = new bytes(5); for (uint i = 0; i < x.length; ++i) - x[i] = byte(i + 1); + x[i] = byte(uint8(i + 1)); assembly { mstore(add(x, 32), "12345678901234567890123456789012") } return x; } @@ -8911,7 +8932,7 @@ BOOST_AUTO_TEST_CASE(cleanup_bytes_types) function f(bytes2 a, uint16 x) returns (uint) { if (a != "ab") return 1; if (x != 0x0102) return 2; - if (bytes3(x) != 0x0102) return 3; + if (bytes3(uint24(x)) != 0x0102) return 3; return 0; } } diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 5af67659..ab7cfb12 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -472,9 +472,9 @@ BOOST_AUTO_TEST_CASE(function_external_types) BOOST_AUTO_TEST_CASE(enum_external_type) { - // bug #1801 SourceUnit const* sourceUnit = nullptr; char const* text = R"( + // test for bug #1801 contract Test { enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } function boo(ActionChoices enumArg) external returns (uint ret) { @@ -977,8 +977,8 @@ BOOST_AUTO_TEST_CASE(private_state_variable) BOOST_AUTO_TEST_CASE(base_class_state_variable_accessor) { - // test for issue #1126 https://github.com/ethereum/cpp-ethereum/issues/1126 char const* text = R"( + // test for issue #1126 https://github.com/ethereum/cpp-ethereum/issues/1126 contract Parent { uint256 public m_aMember; } @@ -2086,115 +2086,6 @@ BOOST_AUTO_TEST_CASE(storage_variable_initialization_with_incorrect_type_string) CHECK_ERROR(text, TypeError, "Type literal_string \"abc\" is not implicitly convertible to expected type uint256."); } -BOOST_AUTO_TEST_CASE(test_fromElementaryTypeName) -{ - - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::Int, 0, 0)) == *make_shared<IntegerType>(256, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 8, 0)) == *make_shared<IntegerType>(8, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 16, 0)) == *make_shared<IntegerType>(16, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 24, 0)) == *make_shared<IntegerType>(24, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 32, 0)) == *make_shared<IntegerType>(32, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 40, 0)) == *make_shared<IntegerType>(40, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 48, 0)) == *make_shared<IntegerType>(48, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 56, 0)) == *make_shared<IntegerType>(56, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 64, 0)) == *make_shared<IntegerType>(64, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 72, 0)) == *make_shared<IntegerType>(72, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 80, 0)) == *make_shared<IntegerType>(80, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 88, 0)) == *make_shared<IntegerType>(88, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 96, 0)) == *make_shared<IntegerType>(96, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 104, 0)) == *make_shared<IntegerType>(104, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 112, 0)) == *make_shared<IntegerType>(112, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 120, 0)) == *make_shared<IntegerType>(120, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 128, 0)) == *make_shared<IntegerType>(128, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 136, 0)) == *make_shared<IntegerType>(136, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 144, 0)) == *make_shared<IntegerType>(144, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 152, 0)) == *make_shared<IntegerType>(152, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 160, 0)) == *make_shared<IntegerType>(160, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 168, 0)) == *make_shared<IntegerType>(168, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 176, 0)) == *make_shared<IntegerType>(176, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 184, 0)) == *make_shared<IntegerType>(184, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 192, 0)) == *make_shared<IntegerType>(192, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 200, 0)) == *make_shared<IntegerType>(200, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 208, 0)) == *make_shared<IntegerType>(208, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 216, 0)) == *make_shared<IntegerType>(216, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 224, 0)) == *make_shared<IntegerType>(224, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 232, 0)) == *make_shared<IntegerType>(232, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 240, 0)) == *make_shared<IntegerType>(240, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 248, 0)) == *make_shared<IntegerType>(248, IntegerType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, 256, 0)) == *make_shared<IntegerType>(256, IntegerType::Modifier::Signed)); - - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UInt, 0, 0)) == *make_shared<IntegerType>(256, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 8, 0)) == *make_shared<IntegerType>(8, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 16, 0)) == *make_shared<IntegerType>(16, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 24, 0)) == *make_shared<IntegerType>(24, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 32, 0)) == *make_shared<IntegerType>(32, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 40, 0)) == *make_shared<IntegerType>(40, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 48, 0)) == *make_shared<IntegerType>(48, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 56, 0)) == *make_shared<IntegerType>(56, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 64, 0)) == *make_shared<IntegerType>(64, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 72, 0)) == *make_shared<IntegerType>(72, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 80, 0)) == *make_shared<IntegerType>(80, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 88, 0)) == *make_shared<IntegerType>(88, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 96, 0)) == *make_shared<IntegerType>(96, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 104, 0)) == *make_shared<IntegerType>(104, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 112, 0)) == *make_shared<IntegerType>(112, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 120, 0)) == *make_shared<IntegerType>(120, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 128, 0)) == *make_shared<IntegerType>(128, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 136, 0)) == *make_shared<IntegerType>(136, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 144, 0)) == *make_shared<IntegerType>(144, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 152, 0)) == *make_shared<IntegerType>(152, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 160, 0)) == *make_shared<IntegerType>(160, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 168, 0)) == *make_shared<IntegerType>(168, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 176, 0)) == *make_shared<IntegerType>(176, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 184, 0)) == *make_shared<IntegerType>(184, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 192, 0)) == *make_shared<IntegerType>(192, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 200, 0)) == *make_shared<IntegerType>(200, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 208, 0)) == *make_shared<IntegerType>(208, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 216, 0)) == *make_shared<IntegerType>(216, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 224, 0)) == *make_shared<IntegerType>(224, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 232, 0)) == *make_shared<IntegerType>(232, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 240, 0)) == *make_shared<IntegerType>(240, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 248, 0)) == *make_shared<IntegerType>(248, IntegerType::Modifier::Unsigned)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, 256, 0)) == *make_shared<IntegerType>(256, IntegerType::Modifier::Unsigned)); - - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::Byte, 0, 0)) == *make_shared<FixedBytesType>(1)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 1, 0)) == *make_shared<FixedBytesType>(1)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 2, 0)) == *make_shared<FixedBytesType>(2)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 3, 0)) == *make_shared<FixedBytesType>(3)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 4, 0)) == *make_shared<FixedBytesType>(4)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 5, 0)) == *make_shared<FixedBytesType>(5)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 6, 0)) == *make_shared<FixedBytesType>(6)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 7, 0)) == *make_shared<FixedBytesType>(7)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 8, 0)) == *make_shared<FixedBytesType>(8)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 9, 0)) == *make_shared<FixedBytesType>(9)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 10, 0)) == *make_shared<FixedBytesType>(10)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 11, 0)) == *make_shared<FixedBytesType>(11)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 12, 0)) == *make_shared<FixedBytesType>(12)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 13, 0)) == *make_shared<FixedBytesType>(13)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 14, 0)) == *make_shared<FixedBytesType>(14)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 15, 0)) == *make_shared<FixedBytesType>(15)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 16, 0)) == *make_shared<FixedBytesType>(16)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 17, 0)) == *make_shared<FixedBytesType>(17)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 18, 0)) == *make_shared<FixedBytesType>(18)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 19, 0)) == *make_shared<FixedBytesType>(19)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 20, 0)) == *make_shared<FixedBytesType>(20)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 21, 0)) == *make_shared<FixedBytesType>(21)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 22, 0)) == *make_shared<FixedBytesType>(22)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 23, 0)) == *make_shared<FixedBytesType>(23)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 24, 0)) == *make_shared<FixedBytesType>(24)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 25, 0)) == *make_shared<FixedBytesType>(25)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 26, 0)) == *make_shared<FixedBytesType>(26)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 27, 0)) == *make_shared<FixedBytesType>(27)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 28, 0)) == *make_shared<FixedBytesType>(28)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 29, 0)) == *make_shared<FixedBytesType>(29)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 30, 0)) == *make_shared<FixedBytesType>(30)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 31, 0)) == *make_shared<FixedBytesType>(31)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, 32, 0)) == *make_shared<FixedBytesType>(32)); - - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::Fixed, 0, 0)) == *make_shared<FixedPointType>(128, 18, FixedPointType::Modifier::Signed)); - BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UFixed, 0, 0)) == *make_shared<FixedPointType>(128, 18, FixedPointType::Modifier::Unsigned)); -} - BOOST_AUTO_TEST_CASE(test_byte_is_alias_of_byte1) { char const* text = R"( @@ -2275,13 +2166,12 @@ BOOST_AUTO_TEST_CASE(constant_string_literal_disallows_assignment) contract Test { string constant x = "abefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabca"; function f() public { + // Even if this is made possible in the future, we should not allow assignment + // to elements of constant arrays. x[0] = "f"; } } )"; - - // Even if this is made possible in the future, we should not allow assignment - // to elements of constant arrays. CHECK_ERROR(text, TypeError, "Index access for string is not possible."); } @@ -2382,11 +2272,11 @@ BOOST_AUTO_TEST_CASE(overloaded_function_cannot_resolve) BOOST_AUTO_TEST_CASE(ambiguous_overloaded_function) { - // literal 1 can be both converted to uint and uint8, so the call is ambiguous. char const* sourceCode = R"( contract test { function f(uint8 a) public returns (uint) { return a; } - function f(uint a) public returns (uint) { return 2*a; } + function f(uint a) public returns (uint) { return 2 * a; } + // literal 1 can be both converted to uint and uint8, so the call is ambiguous. function g() public returns (uint) { return f(1); } } )"; @@ -2809,12 +2699,12 @@ BOOST_AUTO_TEST_CASE(function_argument_storage_to_mem) BOOST_AUTO_TEST_CASE(mem_array_assignment_changes_base_type) { - // Such an assignment is possible in storage, but not in memory - // (because it would incur an otherwise unnecessary copy). - // This requirement might be lifted, though. char const* sourceCode = R"( contract C { function f(uint8[] memory x) private { + // Such an assignment is possible in storage, but not in memory + // (because it would incur an otherwise unnecessary copy). + // This requirement might be lifted, though. uint[] memory y = x; } } @@ -3358,13 +3248,13 @@ BOOST_AUTO_TEST_CASE(using_for_mismatch) BOOST_AUTO_TEST_CASE(using_for_not_used) { - // This is an error because the function is only bound to uint. - // Had it been bound to *, it would have worked. char const* text = R"( library D { function double(uint self) public returns (uint) { return 2; } } contract C { using D for uint; function f(uint16 a) public returns (uint) { + // This is an error because the function is only bound to uint. + // Had it been bound to *, it would have worked. return a.double(); } } @@ -3386,12 +3276,12 @@ BOOST_AUTO_TEST_CASE(library_memory_struct) BOOST_AUTO_TEST_CASE(using_for_arbitrary_mismatch) { - // Bound to a, but self type does not match. char const* text = R"( library D { function double(bytes32 self) public returns (uint) { return 2; } } contract C { using D for *; function f(uint a) public returns (uint) { + // Bound to a, but self type does not match. return a.double(); } } @@ -3859,19 +3749,6 @@ BOOST_AUTO_TEST_CASE(conditional_with_all_types) CHECK_SUCCESS(text); } -BOOST_AUTO_TEST_CASE(index_access_for_bytes) -{ - char const* text = R"( - contract C { - bytes20 x; - function f(bytes16 b) public { - b[uint(x[2])]; - } - } - )"; - CHECK_SUCCESS(text); -} - BOOST_AUTO_TEST_CASE(uint7_and_uintM_as_identifier) { char const* text = R"( @@ -4769,20 +4646,19 @@ BOOST_AUTO_TEST_CASE(illegal_override_payable_nonpayable) BOOST_AUTO_TEST_CASE(function_variable_mixin) { - // bug #1798 (cpp-ethereum), related to #1286 (solidity) - char const* text = R"( - contract attribute { - bool ok = false; - } - contract func { - function ok() public returns (bool) { return true; } - } - - contract attr_func is attribute, func { - function checkOk() public returns (bool) { return ok(); } - } - )"; - CHECK_ERROR(text, DeclarationError, "Identifier already declared."); + char const* text = R"( + // bug #1798 (cpp-ethereum), related to #1286 (solidity) + contract attribute { + bool ok = false; + } + contract func { + function ok() public returns (bool) { return true; } + } + contract attr_func is attribute, func { + function checkOk() public returns (bool) { return ok(); } + } + )"; + CHECK_ERROR(text, DeclarationError, "Identifier already declared."); } BOOST_AUTO_TEST_CASE(calling_payable) @@ -5492,14 +5368,15 @@ BOOST_AUTO_TEST_CASE(invalid_address_length_long) BOOST_AUTO_TEST_CASE(address_test_for_bug_in_implementation) { - // A previous implementation claimed the string would be an address char const* text = R"( + // A previous implementation claimed the string would be an address contract AddrString { address public test = "0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c"; } )"; CHECK_ERROR(text, TypeError, "is not implicitly convertible to expected type address"); text = R"( + // A previous implementation claimed the string would be an address contract AddrString { function f() public returns (address) { return "0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c"; @@ -5511,8 +5388,8 @@ BOOST_AUTO_TEST_CASE(address_test_for_bug_in_implementation) BOOST_AUTO_TEST_CASE(early_exit_on_fatal_errors) { - // This tests a crash that occured because we did not stop for fatal errors. char const* text = R"( + // This tests a crash that occured because we did not stop for fatal errors. contract C { struct S { ftring a; @@ -6059,9 +5936,10 @@ BOOST_AUTO_TEST_CASE(callable_crash) BOOST_AUTO_TEST_CASE(error_transfer_non_payable_fallback) { - // This used to be a test for a.transfer to generate a warning - // because A's fallback function is not payable. char const* text = R"( + // This used to be a test for a.transfer to generate a warning + // because A's fallback function is not payable. + contract A { function() public {} } @@ -6082,9 +5960,10 @@ BOOST_AUTO_TEST_CASE(error_transfer_non_payable_fallback) BOOST_AUTO_TEST_CASE(error_transfer_no_fallback) { - // This used to be a test for a.transfer to generate a warning - // because A does not have a payable fallback function. - std::string text = R"( + char const* text = R"( + // This used to be a test for a.transfer to generate a warning + // because A does not have a payable fallback function. + contract A {} contract B { @@ -6103,9 +5982,10 @@ BOOST_AUTO_TEST_CASE(error_transfer_no_fallback) BOOST_AUTO_TEST_CASE(error_send_non_payable_fallback) { - // This used to be a test for a.send to generate a warning - // because A does not have a payable fallback function. - std::string text = R"( + char const* text = R"( + // This used to be a test for a.send to generate a warning + // because A does not have a payable fallback function. + contract A { function() public {} } @@ -6126,9 +6006,10 @@ BOOST_AUTO_TEST_CASE(error_send_non_payable_fallback) BOOST_AUTO_TEST_CASE(does_not_error_transfer_payable_fallback) { - // This used to be a test for a.transfer to generate a warning - // because A does not have a payable fallback function. char const* text = R"( + // This used to be a test for a.transfer to generate a warning + // because A does not have a payable fallback function. + contract A { function() payable public {} } @@ -6428,8 +6309,8 @@ BOOST_AUTO_TEST_CASE(using_this_in_constructor) BOOST_AUTO_TEST_CASE(do_not_crash_on_not_lvalue) { - // This checks for a bug that caused a crash because of continued analysis. char const* text = R"( + // This checks for a bug that caused a crash because of continued analysis. contract C { mapping (uint => uint) m; function f() public { @@ -6635,8 +6516,8 @@ BOOST_AUTO_TEST_CASE(library_function_without_implementation) BOOST_AUTO_TEST_CASE(using_for_with_non_library) { - // This tests a crash that was resolved by making the first error fatal. char const* text = R"( + // This tests a crash that was resolved by making the first error fatal. library L { struct S { uint d; } using S for S; @@ -6858,7 +6739,7 @@ BOOST_AUTO_TEST_CASE(array_length_invalid_expression) BOOST_AUTO_TEST_CASE(warn_about_address_members_on_contract) { - std::string text = R"( + char const* text = R"( contract C { function f() view public { this.balance; @@ -6919,7 +6800,7 @@ BOOST_AUTO_TEST_CASE(warn_about_address_members_on_contract) BOOST_AUTO_TEST_CASE(warn_about_address_members_on_non_this_contract) { - std::string text = R"( + char const* text = R"( contract C { function f() view public { C c; diff --git a/test/libsolidity/SolidityOptimizer.cpp b/test/libsolidity/SolidityOptimizer.cpp index afce1823..3a8585f7 100644 --- a/test/libsolidity/SolidityOptimizer.cpp +++ b/test/libsolidity/SolidityOptimizer.cpp @@ -216,7 +216,7 @@ BOOST_AUTO_TEST_CASE(array_copy) data1[i] = msg.data[i]; data2 = data1; l = data2.length; - y = uint(data2[x]); + y = uint(uint40(data2[x])); } } )"; diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp index e80b3394..0797b53b 100644 --- a/test/libsolidity/SolidityParser.cpp +++ b/test/libsolidity/SolidityParser.cpp @@ -112,52 +112,6 @@ while(0) BOOST_AUTO_TEST_SUITE(SolidityParser) -BOOST_AUTO_TEST_CASE(multiple_return_param_trailing_comma) -{ - char const* text = R"( - contract test { - function() returns (uint a, uint b,) {} - } - )"; - CHECK_PARSE_ERROR(text, "Unexpected trailing comma in parameter list."); -} - -BOOST_AUTO_TEST_CASE(multiple_modifier_arg_trailing_comma) -{ - char const* text = R"( - contract test { - modifier modTest(uint a, uint b,) { _; } - function(uint a) {} - } - )"; - CHECK_PARSE_ERROR(text, "Unexpected trailing comma in parameter list."); -} - -BOOST_AUTO_TEST_CASE(multiple_event_arg_trailing_comma) -{ - char const* text = R"( - contract test { - event Test(uint a, uint b,); - function(uint a) {} - } - )"; - CHECK_PARSE_ERROR(text, "Unexpected trailing comma in parameter list."); -} - -BOOST_AUTO_TEST_CASE(two_exact_functions) -{ - char const* text = R"( - contract test { - function fun(uint a) returns(uint r) { return a; } - function fun(uint a) returns(uint r) { return a; } - } - )"; - // with support of overloaded functions, during parsing, - // we can't determine whether they match exactly, however - // it will throw DeclarationError in following stage. - BOOST_CHECK(successParse(text)); -} - BOOST_AUTO_TEST_CASE(function_natspec_documentation) { char const* text = R"( @@ -334,57 +288,6 @@ BOOST_AUTO_TEST_CASE(natspec_docstring_after_signature) "Shouldn't get natspec docstring for this function"); } -BOOST_AUTO_TEST_CASE(struct_definition) -{ - char const* text = R"( - contract test { - uint256 stateVar; - struct MyStructName { - address addr; - uint256 count; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(mapping) -{ - char const* text = R"( - contract test { - mapping(address => bytes32) names; - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(mapping_in_struct) -{ - char const* text = R"( - contract test { - struct test_struct { - address addr; - uint256 count; - mapping(bytes32 => test_struct) self_reference; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(mapping_to_mapping_in_struct) -{ - char const* text = R"( - contract test { - struct test_struct { - address addr; - mapping (uint64 => mapping (bytes32 => uint)) complex_mapping; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - BOOST_AUTO_TEST_CASE(variable_definition) { char const* text = R"( @@ -440,112 +343,6 @@ BOOST_AUTO_TEST_CASE(complex_expression) BOOST_CHECK(successParse(text)); } -BOOST_AUTO_TEST_CASE(exp_expression) -{ - char const* text = R"( - contract test { - function fun(uint256 a) { - uint256 x = 3 ** a; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(while_loop) -{ - char const* text = R"( - contract test { - function fun(uint256 a) { - while (true) { uint256 x = 1; break; continue; } x = 9; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(for_loop_vardef_initexpr) -{ - char const* text = R"( - contract test { - function fun(uint256 a) { - for (uint256 i = 0; i < 10; i++) { - uint256 x = i; break; continue; - } - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(for_loop_simple_initexpr) -{ - char const* text = R"( - contract test { - function fun(uint256 a) { - uint256 i =0; - for (i = 0; i < 10; i++) { - uint256 x = i; break; continue; - } - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(for_loop_simple_noexpr) -{ - char const* text = R"( - contract test { - function fun(uint256 a) { - uint256 i =0; - for (;;) { - uint256 x = i; break; continue; - } - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(for_loop_single_stmt_body) -{ - char const* text = R"( - contract test { - function fun(uint256 a) { - uint256 i = 0; - for (i = 0; i < 10; i++) - continue; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(if_statement) -{ - char const* text = R"( - contract test { - function fun(uint256 a) { - if (a >= 8) { return 2; } else { var b = 7; } - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(else_if_statement) -{ - char const* text = R"( - contract test { - function fun(uint256 a) returns (address b) { - if (a < 0) b = 0x67; else if (a == 0) b = 0x12; else b = 0x78; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - BOOST_AUTO_TEST_CASE(statement_starting_with_type_conversion) { char const* text = R"( @@ -673,108 +470,6 @@ BOOST_AUTO_TEST_CASE(contract_multiple_inheritance_with_arguments) BOOST_CHECK(successParse(text)); } -BOOST_AUTO_TEST_CASE(placeholder_in_function_context) -{ - char const* text = R"( - contract c { - function fun() returns (uint r) { - var _ = 8; - return _ + 1; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(modifier) -{ - char const* text = R"( - contract c { - modifier mod { if (msg.sender == 0) _; } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(modifier_arguments) -{ - char const* text = R"( - contract c { - modifier mod(address a) { if (msg.sender == a) _; } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(modifier_invocation) -{ - char const* text = R"( - contract c { - modifier mod1(uint a) { if (msg.sender == a) _; } - modifier mod2 { if (msg.sender == 2) _; } - function f() mod1(7) mod2 { } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(fallback_function) -{ - char const* text = R"( - contract c { - function() { } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(event) -{ - char const* text = R"( - contract c { - event e(); - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(event_arguments) -{ - char const* text = R"( - contract c { - event e(uint a, bytes32 s); - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(event_arguments_indexed) -{ - char const* text = R"( - contract c { - event e(uint a, bytes32 indexed s, bool indexed b); - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(visibility_specifiers) -{ - char const* text = R"( - contract c { - uint private a; - uint internal b; - uint public c; - uint d; - function f() {} - function f_priv() private {} - function f_public() public {} - function f_internal() internal {} - } - )"; - BOOST_CHECK(successParse(text)); -} - BOOST_AUTO_TEST_CASE(multiple_visibility_specifiers) { char const* text = R"( @@ -791,108 +486,6 @@ BOOST_AUTO_TEST_CASE(multiple_visibility_specifiers) CHECK_PARSE_ERROR(text, "Visibility already specified as \"private\"."); } -BOOST_AUTO_TEST_CASE(literal_constants_with_ether_subdenominations) -{ - char const* text = R"( - contract c { - function c () - { - a = 1 wei; - b = 2 szabo; - c = 3 finney; - b = 4 ether; - } - uint256 a; - uint256 b; - uint256 c; - uint256 d; - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(literal_constants_with_ether_subdenominations_in_expressions) -{ - char const* text = R"( - contract c { - function c () - { - a = 1 wei * 100 wei + 7 szabo - 3; - } - uint256 a; - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(enum_valid_declaration) -{ - char const* text = R"( - contract c { - enum validEnum { Value1, Value2, Value3, Value4 } - function c () - { - a = foo.Value3; - } - uint256 a; - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(external_function) -{ - char const* text = R"( - contract c { - function x() external {} - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(arrays_in_storage) -{ - char const* text = R"( - contract c { - uint[10] a; - uint[] a2; - struct x { uint[2**20] b; y[0] c; } - struct y { uint d; mapping(uint=>x)[] e; } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(arrays_in_events) -{ - char const* text = R"( - contract c { - event e(uint[10] a, bytes7[8] indexed b, c[3] x); - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(arrays_in_expressions) -{ - char const* text = R"( - contract c { - function f() { c[10] a = 7; uint8[10 * 2] x; } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(multi_arrays) -{ - char const* text = R"( - contract c { - mapping(uint => mapping(uint => int8)[8][][9])[] x; - } - )"; - BOOST_CHECK(successParse(text)); -} - BOOST_AUTO_TEST_CASE(keyword_is_reserved) { auto keywords = { @@ -923,39 +516,6 @@ BOOST_AUTO_TEST_CASE(keyword_is_reserved) } } -BOOST_AUTO_TEST_CASE(location_specifiers_for_params) -{ - char const* text = R"( - contract Foo { - function f(uint[] storage constant x, uint[] memory y) { } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(location_specifiers_for_locals) -{ - char const* text = R"( - contract Foo { - function f() { - uint[] storage x; - uint[] memory y; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(library_simple) -{ - char const* text = R"( - library Lib { - function f() { } - } - )"; - BOOST_CHECK(successParse(text)); -} - BOOST_AUTO_TEST_CASE(member_access_parser_ambiguity) { char const* text = R"( @@ -1000,97 +560,6 @@ BOOST_AUTO_TEST_CASE(complex_import) BOOST_CHECK(successParse(text)); } -BOOST_AUTO_TEST_CASE(from_is_not_keyword) -{ - // "from" is not a keyword although it is used as a keyword in import directives. - char const* text = R"( - contract from { - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(inline_array_declaration) -{ - char const* text = R"( - contract c { - uint[] a; - function f() returns (uint, uint) { - a = [1,2,3]; - return (a[3], [2,3,4][0]); - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(conditional_true_false_literal) -{ - char const* text = R"( - contract A { - function f() { - uint x = true ? 1 : 0; - uint y = false ? 0 : 1; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(conditional_with_constants) -{ - char const* text = R"( - contract A { - function f() { - uint x = 3 > 0 ? 3 : 0; - uint y = (3 > 0) ? 3 : 0; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(conditional_with_variables) -{ - char const* text = R"( - contract A { - function f() { - uint x = 3; - uint y = 1; - uint z = (x > y) ? x : y; - uint w = x > y ? x : y; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(conditional_multiple) -{ - char const* text = R"( - contract A { - function f() { - uint x = 3 < 0 ? 2 > 1 ? 2 : 1 : 7 > 2 ? 7 : 6; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(conditional_with_assignment) -{ - char const* text = R"( - contract A { - function f() { - uint y = 1; - uint x = 3 < 0 ? x = 3 : 6; - true ? x = 3 : 4; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - BOOST_AUTO_TEST_CASE(recursion_depth1) { string text("contract C { bytes"); @@ -1127,117 +596,6 @@ BOOST_AUTO_TEST_CASE(recursion_depth4) CHECK_PARSE_ERROR(text, "Maximum recursion depth reached during parsing"); } -BOOST_AUTO_TEST_CASE(declaring_fixed_and_ufixed_variables) -{ - char const* text = R"( - contract A { - fixed40x40 storeMe; - function f(ufixed x, fixed32x32 y) { - ufixed8x8 a; - fixed b; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(declaring_fixed_literal_variables) -{ - char const* text = R"( - contract A { - fixed40x40 pi = 3.14; - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(function_type_in_expression) -{ - char const* text = R"( - contract test { - function f(uint x, uint y) returns (uint a) {} - function g() { - function (uint, uint) internal returns (uint) f1 = f; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(function_type_as_storage_variable) -{ - char const* text = R"( - contract test { - function (uint, uint) internal returns (uint) f1; - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(function_type_as_storage_variable_with_assignment) -{ - char const* text = R"( - contract test { - function f(uint x, uint y) returns (uint a) {} - function (uint, uint) internal returns (uint) f1 = f; - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(function_type_in_struct) -{ - char const* text = R"( - contract test { - struct S { - function (uint x, uint y) internal returns (uint a) f; - function (uint, uint) external returns (uint) g; - uint d; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(function_type_as_parameter) -{ - char const* text = R"( - contract test { - function f(function(uint) external returns (uint) g) internal returns (uint a) { - return g(1); - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(calling_function) -{ - char const* text = R"( - contract test { - function f() { - function() returns(function() returns(function() returns(function() returns(uint)))) x; - uint y; - y = x()()()(); - } - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(mapping_and_array_of_functions) -{ - char const* text = R"( - contract test { - mapping (address => function() internal returns (uint)) a; - mapping (address => function() external) b; - mapping (address => function() external[]) c; - function() external[] d; - } - )"; - BOOST_CHECK(successParse(text)); -} - BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/SolidityTypes.cpp b/test/libsolidity/SolidityTypes.cpp index 738b24bc..e6928bb8 100644 --- a/test/libsolidity/SolidityTypes.cpp +++ b/test/libsolidity/SolidityTypes.cpp @@ -36,6 +36,33 @@ namespace test BOOST_AUTO_TEST_SUITE(SolidityTypes) +BOOST_AUTO_TEST_CASE(int_types) +{ + BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::Int, 0, 0)) == *make_shared<IntegerType>(256, IntegerType::Modifier::Signed)); + for (unsigned i = 8; i <= 256; i += 8) + BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::IntM, i, 0)) == *make_shared<IntegerType>(i, IntegerType::Modifier::Signed)); +} + +BOOST_AUTO_TEST_CASE(uint_types) +{ + BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UInt, 0, 0)) == *make_shared<IntegerType>(256, IntegerType::Modifier::Unsigned)); + for (unsigned i = 8; i <= 256; i += 8) + BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UIntM, i, 0)) == *make_shared<IntegerType>(i, IntegerType::Modifier::Unsigned)); +} + +BOOST_AUTO_TEST_CASE(byte_types) +{ + BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::Byte, 0, 0)) == *make_shared<FixedBytesType>(1)); + for (unsigned i = 1; i <= 32; i++) + BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::BytesM, i, 0)) == *make_shared<FixedBytesType>(i)); +} + +BOOST_AUTO_TEST_CASE(fixed_types) +{ + BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::Fixed, 0, 0)) == *make_shared<FixedPointType>(128, 18, FixedPointType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(ElementaryTypeNameToken(Token::UFixed, 0, 0)) == *make_shared<FixedPointType>(128, 18, FixedPointType::Modifier::Unsigned)); +} + BOOST_AUTO_TEST_CASE(storage_layout_simple) { MemberList members(MemberList::MemberMap({ diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/dowhile_fine.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/dowhile_fine.sol index 6520672c..55c5edd3 100644 --- a/test/libsolidity/syntaxTests/controlFlow/storageReturn/dowhile_fine.sol +++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/dowhile_fine.sol @@ -23,13 +23,8 @@ contract C { } function k() internal view returns (S storage c) { do { - if (s.f) { - continue; - break; - } - else { - c = s; - } + c = s; + continue; } while(false); } } diff --git a/test/libsolidity/syntaxTests/controlFlow/storageReturn/dowhile_warn.sol b/test/libsolidity/syntaxTests/controlFlow/storageReturn/dowhile_warn.sol index f1a92e9c..7d001c19 100644 --- a/test/libsolidity/syntaxTests/controlFlow/storageReturn/dowhile_warn.sol +++ b/test/libsolidity/syntaxTests/controlFlow/storageReturn/dowhile_warn.sol @@ -21,6 +21,15 @@ contract C { do { if (s.f) { break; + } + else { + c = s; + } + } while(false); + } + function i() internal view returns (S storage c) { + do { + if (s.f) { continue; } else { @@ -28,8 +37,16 @@ contract C { } } while(false); } + function j() internal view returns (S storage c) { + do { + continue; + c = s; + } while(false); + } } // ---- // Warning: (87-98): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning. // Warning: (223-234): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning. // Warning: (440-451): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning. +// Warning: (654-665): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning. +// Warning: (871-882): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning. diff --git a/test/libsolidity/syntaxTests/parsing/arrays_in_events.sol b/test/libsolidity/syntaxTests/parsing/arrays_in_events.sol new file mode 100644 index 00000000..edbc9665 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/arrays_in_events.sol @@ -0,0 +1,3 @@ +contract c { + event e(uint[10] a, bytes7[8] indexed b, c[3] x); +} diff --git a/test/libsolidity/syntaxTests/parsing/arrays_in_expressions.sol b/test/libsolidity/syntaxTests/parsing/arrays_in_expressions.sol new file mode 100644 index 00000000..626e865e --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/arrays_in_expressions.sol @@ -0,0 +1,8 @@ +contract c { + function f() { c[10] a = 7; uint8[10 * 2] x; } +} +// ---- +// Warning: (32-39): Variable is declared as a storage pointer. Use an explicit "storage" keyword to silence this warning. +// Warning: (45-60): Variable is declared as a storage pointer. Use an explicit "storage" keyword to silence this warning. +// TypeError: (32-43): Type int_const 7 is not implicitly convertible to expected type contract c[10] storage pointer. +// Warning: (45-60): Uninitialized storage pointer. Did you mean '<type> memory x'? diff --git a/test/libsolidity/syntaxTests/parsing/arrays_in_storage.sol b/test/libsolidity/syntaxTests/parsing/arrays_in_storage.sol new file mode 100644 index 00000000..9181222e --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/arrays_in_storage.sol @@ -0,0 +1,6 @@ +contract c { + uint[10] a; + uint[] a2; + struct x { uint[2**20] b; y[0] c; } + struct y { uint d; mapping(uint=>x)[] e; } +} diff --git a/test/libsolidity/syntaxTests/parsing/calling_function.sol b/test/libsolidity/syntaxTests/parsing/calling_function.sol new file mode 100644 index 00000000..4c4fc1fc --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/calling_function.sol @@ -0,0 +1,9 @@ +contract test { + function f() { + function() returns(function() returns(function() returns(function() returns(uint)))) x; + uint y; + y = x()()()(); + } +} +// ---- +// Warning: (20-175): No visibility specified. Defaulting to "public". diff --git a/test/libsolidity/syntaxTests/parsing/conditional_multiple.sol b/test/libsolidity/syntaxTests/parsing/conditional_multiple.sol new file mode 100644 index 00000000..c7d11ed6 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/conditional_multiple.sol @@ -0,0 +1,9 @@ +contract A { + function f() { + uint x = 3 < 0 ? 2 > 1 ? 2 : 1 : 7 > 2 ? 7 : 6; + } +} +// ---- +// Warning: (17-93): No visibility specified. Defaulting to "public". +// Warning: (40-46): Unused local variable. +// Warning: (17-93): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/conditional_true_false_literal.sol b/test/libsolidity/syntaxTests/parsing/conditional_true_false_literal.sol new file mode 100644 index 00000000..90974e96 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/conditional_true_false_literal.sol @@ -0,0 +1,11 @@ +contract A { + function f() { + uint x = true ? 1 : 0; + uint y = false ? 0 : 1; + } +} +// ---- +// Warning: (17-100): No visibility specified. Defaulting to "public". +// Warning: (40-46): Unused local variable. +// Warning: (71-77): Unused local variable. +// Warning: (17-100): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/conditional_with_assignment.sol b/test/libsolidity/syntaxTests/parsing/conditional_with_assignment.sol new file mode 100644 index 00000000..6f8040d6 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/conditional_with_assignment.sol @@ -0,0 +1,11 @@ +contract A { + function f() { + uint y = 1; + uint x = 3 < 0 ? x = 3 : 6; + true ? x = 3 : 4; + } +} +// ---- +// Warning: (17-119): No visibility specified. Defaulting to "public". +// Warning: (40-46): Unused local variable. +// Warning: (17-119): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/conditional_with_constants.sol b/test/libsolidity/syntaxTests/parsing/conditional_with_constants.sol new file mode 100644 index 00000000..35da69c6 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/conditional_with_constants.sol @@ -0,0 +1,11 @@ +contract A { + function f() { + uint x = 3 > 0 ? 3 : 0; + uint y = (3 > 0) ? 3 : 0; + } +} +// ---- +// Warning: (17-103): No visibility specified. Defaulting to "public". +// Warning: (40-46): Unused local variable. +// Warning: (72-78): Unused local variable. +// Warning: (17-103): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/conditional_with_variables.sol b/test/libsolidity/syntaxTests/parsing/conditional_with_variables.sol new file mode 100644 index 00000000..eb4c7091 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/conditional_with_variables.sol @@ -0,0 +1,13 @@ +contract A { + function f() { + uint x = 3; + uint y = 1; + uint z = (x > y) ? x : y; + uint w = x > y ? x : y; + } +} +// ---- +// Warning: (17-143): No visibility specified. Defaulting to "public". +// Warning: (80-86): Unused local variable. +// Warning: (114-120): Unused local variable. +// Warning: (17-143): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/declaring_fixed_and_ufixed_variables.sol b/test/libsolidity/syntaxTests/parsing/declaring_fixed_and_ufixed_variables.sol new file mode 100644 index 00000000..8be9667a --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/declaring_fixed_and_ufixed_variables.sol @@ -0,0 +1,14 @@ +contract A { + fixed40x40 storeMe; + function f(ufixed x, fixed32x32 y) { + ufixed8x8 a; + fixed b; + } +} +// ---- +// Warning: (41-121): No visibility specified. Defaulting to "public". +// Warning: (52-60): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (62-74): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (86-97): Unused local variable. +// Warning: (107-114): Unused local variable. +// Warning: (41-121): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/declaring_fixed_literal_variables.sol b/test/libsolidity/syntaxTests/parsing/declaring_fixed_literal_variables.sol new file mode 100644 index 00000000..b0d938a0 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/declaring_fixed_literal_variables.sol @@ -0,0 +1,5 @@ +contract A { + fixed40x40 pi = 3.14; +} +// ---- +// TypeError: (33-37): Type rational_const 157 / 50 is not implicitly convertible to expected type fixed40x40. Try converting to type ufixed16x2 or use an explicit conversion. diff --git a/test/libsolidity/syntaxTests/parsing/else_if_statement.sol b/test/libsolidity/syntaxTests/parsing/else_if_statement.sol new file mode 100644 index 00000000..727e6115 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/else_if_statement.sol @@ -0,0 +1,8 @@ +contract test { + function fun(uint256 a) returns (address b) { + if (a < 0) b = 0x67; else if (a == 0) b = 0x12; else b = 0x78; + } +} +// ---- +// Warning: (20-142): No visibility specified. Defaulting to "public". +// Warning: (20-142): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/enum_valid_declaration.sol b/test/libsolidity/syntaxTests/parsing/enum_valid_declaration.sol new file mode 100644 index 00000000..4c4a1217 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/enum_valid_declaration.sol @@ -0,0 +1,10 @@ +contract c { + enum validEnum { Value1, Value2, Value3, Value4 } + function c() { + a = validEnum.Value3; + } + validEnum a; +} +// ---- +// Warning: (71-121): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead. +// Warning: (71-121): No visibility specified. Defaulting to "public". diff --git a/test/libsolidity/syntaxTests/parsing/event.sol b/test/libsolidity/syntaxTests/parsing/event.sol new file mode 100644 index 00000000..2aaa873f --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/event.sol @@ -0,0 +1,3 @@ +contract c { + event e(); +} diff --git a/test/libsolidity/syntaxTests/parsing/event_arguments.sol b/test/libsolidity/syntaxTests/parsing/event_arguments.sol new file mode 100644 index 00000000..3228853a --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/event_arguments.sol @@ -0,0 +1,3 @@ +contract c { + event e(uint a, bytes32 s); +} diff --git a/test/libsolidity/syntaxTests/parsing/event_arguments_indexed.sol b/test/libsolidity/syntaxTests/parsing/event_arguments_indexed.sol new file mode 100644 index 00000000..d603fc08 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/event_arguments_indexed.sol @@ -0,0 +1,3 @@ +contract c { + event e(uint a, bytes32 indexed s, bool indexed b); +} diff --git a/test/libsolidity/syntaxTests/parsing/exp_expression.sol b/test/libsolidity/syntaxTests/parsing/exp_expression.sol new file mode 100644 index 00000000..cdabb996 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/exp_expression.sol @@ -0,0 +1,9 @@ +contract test { + function fun(uint256 a) { + uint256 x = 3 ** a; + } +} +// ---- +// Warning: (20-79): No visibility specified. Defaulting to "public". +// Warning: (54-63): Unused local variable. +// Warning: (20-79): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/external_function.sol b/test/libsolidity/syntaxTests/parsing/external_function.sol new file mode 100644 index 00000000..3aa3ceec --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/external_function.sol @@ -0,0 +1,5 @@ +contract c { + function x() external {} +} +// ---- +// Warning: (17-41): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/fallback_function.sol b/test/libsolidity/syntaxTests/parsing/fallback_function.sol new file mode 100644 index 00000000..de32b030 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/fallback_function.sol @@ -0,0 +1,5 @@ +contract c { + function() { } +} +// ---- +// Warning: (17-31): No visibility specified. Defaulting to "public". diff --git a/test/libsolidity/syntaxTests/parsing/for_loop_simple_initexpr.sol b/test/libsolidity/syntaxTests/parsing/for_loop_simple_initexpr.sol new file mode 100644 index 00000000..bd86f2f5 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/for_loop_simple_initexpr.sol @@ -0,0 +1,13 @@ +contract test { + function fun(uint256 a) { + uint256 i =0; + for (i = 0; i < 10; i++) { + uint256 x = i; break; continue; + } + } +} +// ---- +// Warning: (20-162): No visibility specified. Defaulting to "public". +// Warning: (33-42): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (115-124): Unused local variable. +// Warning: (20-162): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/for_loop_simple_noexpr.sol b/test/libsolidity/syntaxTests/parsing/for_loop_simple_noexpr.sol new file mode 100644 index 00000000..4a27e0fb --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/for_loop_simple_noexpr.sol @@ -0,0 +1,13 @@ +contract test { + function fun(uint256 a) { + uint256 i =0; + for (;;) { + uint256 x = i; break; continue; + } + } + } +// ---- +// Warning: (24-170): No visibility specified. Defaulting to "public". +// Warning: (37-46): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (115-124): Unused local variable. +// Warning: (24-170): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/for_loop_single_stmt_body.sol b/test/libsolidity/syntaxTests/parsing/for_loop_single_stmt_body.sol new file mode 100644 index 00000000..3df88ef5 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/for_loop_single_stmt_body.sol @@ -0,0 +1,11 @@ +contract test { + function fun(uint256 a) { + uint256 i = 0; + for (i = 0; i < 10; i++) + continue; + } +} +// ---- +// Warning: (20-129): No visibility specified. Defaulting to "public". +// Warning: (33-42): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (20-129): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/for_loop_vardef_initexpr.sol b/test/libsolidity/syntaxTests/parsing/for_loop_vardef_initexpr.sol new file mode 100644 index 00000000..a7c5e8bb --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/for_loop_vardef_initexpr.sol @@ -0,0 +1,12 @@ +contract test { + function fun(uint256 a) { + for (uint256 i = 0; i < 10; i++) { + uint256 x = i; break; continue; + } + } +} +// ---- +// Warning: (20-148): No visibility specified. Defaulting to "public". +// Warning: (33-42): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (101-110): Unused local variable. +// Warning: (20-148): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/from_is_not_keyword.sol b/test/libsolidity/syntaxTests/parsing/from_is_not_keyword.sol new file mode 100644 index 00000000..38175572 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/from_is_not_keyword.sol @@ -0,0 +1,3 @@ +// "from" is not a keyword although it is used as a keyword in import directives. +contract from { +} diff --git a/test/libsolidity/syntaxTests/parsing/function_normal_comments.sol b/test/libsolidity/syntaxTests/parsing/function_normal_comments.sol new file mode 100644 index 00000000..c7a023ac --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/function_normal_comments.sol @@ -0,0 +1,10 @@ +contract test { + uint256 stateVar; + // We won't see this comment + function functionName(bytes32 input) returns (bytes32 out) {} +} +// ---- +// Warning: (75-136): No visibility specified. Defaulting to "public". +// Warning: (97-110): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (121-132): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (75-136): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/function_type_as_parameter.sol b/test/libsolidity/syntaxTests/parsing/function_type_as_parameter.sol new file mode 100644 index 00000000..4075d74a --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/function_type_as_parameter.sol @@ -0,0 +1,5 @@ +contract test { + function f(function(uint) external returns (uint) g) internal returns (uint a) { + return g(1); + } +} diff --git a/test/libsolidity/syntaxTests/parsing/function_type_as_storage_variable.sol b/test/libsolidity/syntaxTests/parsing/function_type_as_storage_variable.sol new file mode 100644 index 00000000..e3d41f48 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/function_type_as_storage_variable.sol @@ -0,0 +1,3 @@ +contract test { + function (uint, uint) internal returns (uint) f1; +} diff --git a/test/libsolidity/syntaxTests/parsing/function_type_as_storage_variable_with_assignment.sol b/test/libsolidity/syntaxTests/parsing/function_type_as_storage_variable_with_assignment.sol new file mode 100644 index 00000000..3b784733 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/function_type_as_storage_variable_with_assignment.sol @@ -0,0 +1,10 @@ +contract test { + function f(uint x, uint y) returns (uint a) {} + function (uint, uint) internal returns (uint) f1 = f; +} +// ---- +// Warning: (20-66): No visibility specified. Defaulting to "public". +// Warning: (31-37): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (39-45): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (56-62): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (20-66): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/function_type_in_expression.sol b/test/libsolidity/syntaxTests/parsing/function_type_in_expression.sol new file mode 100644 index 00000000..fd6447c7 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/function_type_in_expression.sol @@ -0,0 +1,15 @@ +contract test { + function f(uint x, uint y) returns (uint a) {} + function g() { + function (uint, uint) internal returns (uint) f1 = f; + } +} +// ---- +// Warning: (20-66): No visibility specified. Defaulting to "public". +// Warning: (31-37): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (39-45): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (56-62): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (71-153): No visibility specified. Defaulting to "public". +// Warning: (94-142): Unused local variable. +// Warning: (20-66): Function state mutability can be restricted to pure +// Warning: (71-153): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/function_type_in_struct.sol b/test/libsolidity/syntaxTests/parsing/function_type_in_struct.sol new file mode 100644 index 00000000..d3c84678 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/function_type_in_struct.sol @@ -0,0 +1,11 @@ +contract test { + struct S { + function (uint x, uint y) internal returns (uint a) f; + function (uint, uint) external returns (uint) g; + uint d; + } +} +// ---- +// Warning: (49-55): Naming function type parameters is deprecated. +// Warning: (57-63): Naming function type parameters is deprecated. +// Warning: (83-89): Naming function type return parameters is deprecated. diff --git a/test/libsolidity/syntaxTests/parsing/if_statement.sol b/test/libsolidity/syntaxTests/parsing/if_statement.sol new file mode 100644 index 00000000..0819cb9f --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/if_statement.sol @@ -0,0 +1,11 @@ +contract test { + function fun(uint256 a) returns (uint) { + if (a >= 8) { return 2; } else { var b = 7; } + } +} +// ---- +// Warning: (102-107): Use of the "var" keyword is deprecated. +// Warning: (102-111): The type of this variable was inferred as uint8, which can hold values between 0 and 255. This is probably not desired. Use an explicit type to silence this warning. +// Warning: (20-120): No visibility specified. Defaulting to "public". +// Warning: (102-107): Unused local variable. +// Warning: (20-120): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/inline_array_declaration.sol b/test/libsolidity/syntaxTests/parsing/inline_array_declaration.sol new file mode 100644 index 00000000..f42f8f16 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/inline_array_declaration.sol @@ -0,0 +1,9 @@ +contract c { + uint[] a; + function f() returns (uint, uint) { + a = [1,2,3]; + return (a[3], [2,3,4][0]); + } +} +// ---- +// Warning: (31-128): No visibility specified. Defaulting to "public". diff --git a/test/libsolidity/syntaxTests/parsing/library_simple.sol b/test/libsolidity/syntaxTests/parsing/library_simple.sol new file mode 100644 index 00000000..fcf2638e --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/library_simple.sol @@ -0,0 +1,6 @@ +library Lib { + function f() { } +} +// ---- +// Warning: (18-34): No visibility specified. Defaulting to "public". +// Warning: (18-34): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/literal_constants_with_ether_subdenominations.sol b/test/libsolidity/syntaxTests/parsing/literal_constants_with_ether_subdenominations.sol new file mode 100644 index 00000000..452b52c7 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/literal_constants_with_ether_subdenominations.sol @@ -0,0 +1,16 @@ +contract c { + function f() + { + a = 1 wei; + b = 2 szabo; + c = 3 finney; + b = 4 ether; + } + uint256 a; + uint256 b; + uint256 c; + uint256 d; +} +// ---- +// Warning: (163-172): This declaration shadows an existing declaration. +// Warning: (17-128): No visibility specified. Defaulting to "public". diff --git a/test/libsolidity/syntaxTests/parsing/literal_constants_with_ether_subdenominations_in_expressions.sol b/test/libsolidity/syntaxTests/parsing/literal_constants_with_ether_subdenominations_in_expressions.sol new file mode 100644 index 00000000..d2cdc875 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/literal_constants_with_ether_subdenominations_in_expressions.sol @@ -0,0 +1,10 @@ +contract c { + function c () + { + a = 1 wei * 100 wei + 7 szabo - 3; + } + uint256 a; +} +// ---- +// Warning: (17-86): Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead. +// Warning: (17-86): No visibility specified. Defaulting to "public". diff --git a/test/libsolidity/syntaxTests/parsing/location_specifiers_for_locals.sol b/test/libsolidity/syntaxTests/parsing/location_specifiers_for_locals.sol new file mode 100644 index 00000000..5d6c8dc5 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/location_specifiers_for_locals.sol @@ -0,0 +1,12 @@ +contract Foo { + function f() { + uint[] storage x; + uint[] memory y; + } +} +// ---- +// Warning: (42-58): Uninitialized storage pointer. +// Warning: (19-90): No visibility specified. Defaulting to "public". +// Warning: (42-58): Unused local variable. +// Warning: (68-83): Unused local variable. +// Warning: (19-90): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/location_specifiers_for_params.sol b/test/libsolidity/syntaxTests/parsing/location_specifiers_for_params.sol new file mode 100644 index 00000000..e021182a --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/location_specifiers_for_params.sol @@ -0,0 +1,5 @@ +contract Foo { + function f(uint[] storage constant x, uint[] memory y) internal { } +} +// ---- +// TypeError: (30-55): Storage location has to be "memory" (or unspecified) for constants. diff --git a/test/libsolidity/syntaxTests/parsing/mapping.sol b/test/libsolidity/syntaxTests/parsing/mapping.sol new file mode 100644 index 00000000..d6bf3f14 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/mapping.sol @@ -0,0 +1,3 @@ +contract test { + mapping(address => bytes32) names; +} diff --git a/test/libsolidity/syntaxTests/parsing/mapping_and_array_of_functions.sol b/test/libsolidity/syntaxTests/parsing/mapping_and_array_of_functions.sol new file mode 100644 index 00000000..b7cf34e4 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/mapping_and_array_of_functions.sol @@ -0,0 +1,6 @@ +contract test { + mapping (address => function() internal returns (uint)) a; + mapping (address => function() external) b; + mapping (address => function() external[]) c; + function() external[] d; +} diff --git a/test/libsolidity/syntaxTests/parsing/mapping_in_struct.sol b/test/libsolidity/syntaxTests/parsing/mapping_in_struct.sol new file mode 100644 index 00000000..980d5750 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/mapping_in_struct.sol @@ -0,0 +1,7 @@ +contract test { + struct test_struct { + address addr; + uint256 count; + mapping(bytes32 => test_struct) self_reference; + } +} diff --git a/test/libsolidity/syntaxTests/parsing/mapping_to_mapping_in_struct.sol b/test/libsolidity/syntaxTests/parsing/mapping_to_mapping_in_struct.sol new file mode 100644 index 00000000..c06220b7 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/mapping_to_mapping_in_struct.sol @@ -0,0 +1,6 @@ +contract test { + struct test_struct { + address addr; + mapping (uint64 => mapping (bytes32 => uint)) complex_mapping; + } +} diff --git a/test/libsolidity/syntaxTests/parsing/modifier.sol b/test/libsolidity/syntaxTests/parsing/modifier.sol new file mode 100644 index 00000000..3e659dcf --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/modifier.sol @@ -0,0 +1,3 @@ +contract c { + modifier mod { if (msg.sender == 0) _; } +} diff --git a/test/libsolidity/syntaxTests/parsing/modifier_arguments.sol b/test/libsolidity/syntaxTests/parsing/modifier_arguments.sol new file mode 100644 index 00000000..27b5b13b --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/modifier_arguments.sol @@ -0,0 +1,3 @@ +contract c { + modifier mod(address a) { if (msg.sender == a) _; } +} diff --git a/test/libsolidity/syntaxTests/parsing/modifier_invocation.sol b/test/libsolidity/syntaxTests/parsing/modifier_invocation.sol new file mode 100644 index 00000000..cb2f2985 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/modifier_invocation.sol @@ -0,0 +1,8 @@ +contract c { + modifier mod1(uint a) { if (msg.sender == address(a)) _; } + modifier mod2 { if (msg.sender == address(2)) _; } + function f() mod1(7) mod2 { } +} +// ---- +// Warning: (135-164): No visibility specified. Defaulting to "public". +// Warning: (135-164): Function state mutability can be restricted to view diff --git a/test/libsolidity/syntaxTests/parsing/multi_arrays.sol b/test/libsolidity/syntaxTests/parsing/multi_arrays.sol new file mode 100644 index 00000000..ef20ecee --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/multi_arrays.sol @@ -0,0 +1,3 @@ +contract c { + mapping(uint => mapping(uint => int8)[8][][9])[] x; +} diff --git a/test/libsolidity/syntaxTests/parsing/multiple_event_arg_trailing_comma.sol b/test/libsolidity/syntaxTests/parsing/multiple_event_arg_trailing_comma.sol new file mode 100644 index 00000000..bfbe7e5c --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/multiple_event_arg_trailing_comma.sol @@ -0,0 +1,6 @@ +contract test { + event Test(uint a, uint b,); + function(uint a) {} +} +// ---- +// ParserError: (45-46): Unexpected trailing comma in parameter list. diff --git a/test/libsolidity/syntaxTests/parsing/multiple_functions_natspec_documentation.sol b/test/libsolidity/syntaxTests/parsing/multiple_functions_natspec_documentation.sol new file mode 100644 index 00000000..95a4d1e7 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/multiple_functions_natspec_documentation.sol @@ -0,0 +1,28 @@ +contract test { + uint256 stateVar; + /// This is test function 1 + function functionName1(bytes32 input) returns (bytes32 out) {} + /// This is test function 2 + function functionName2(bytes32 input) returns (bytes32 out) {} + // nothing to see here + function functionName3(bytes32 input) returns (bytes32 out) {} + /// This is test function 4 + function functionName4(bytes32 input) returns (bytes32 out) {} +} +// ---- +// Warning: (74-136): No visibility specified. Defaulting to "public". +// Warning: (97-110): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (121-132): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (173-235): No visibility specified. Defaulting to "public". +// Warning: (196-209): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (220-231): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (267-329): No visibility specified. Defaulting to "public". +// Warning: (290-303): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (314-325): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (366-428): No visibility specified. Defaulting to "public". +// Warning: (389-402): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (413-424): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (74-136): Function state mutability can be restricted to pure +// Warning: (173-235): Function state mutability can be restricted to pure +// Warning: (267-329): Function state mutability can be restricted to pure +// Warning: (366-428): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/multiple_modifier_arg_trailing_comma.sol b/test/libsolidity/syntaxTests/parsing/multiple_modifier_arg_trailing_comma.sol new file mode 100644 index 00000000..eb206fb7 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/multiple_modifier_arg_trailing_comma.sol @@ -0,0 +1,6 @@ +contract test { + modifier modTest(uint a, uint b,) { _; } + function(uint a) {} +} +// ---- +// ParserError: (51-52): Unexpected trailing comma in parameter list. diff --git a/test/libsolidity/syntaxTests/parsing/multiple_return_param_trailing_comma.sol b/test/libsolidity/syntaxTests/parsing/multiple_return_param_trailing_comma.sol new file mode 100644 index 00000000..2dd8f196 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/multiple_return_param_trailing_comma.sol @@ -0,0 +1,5 @@ +contract test { + function() returns (uint a, uint b,) {} +} +// ---- +// ParserError: (54-55): Unexpected trailing comma in parameter list. diff --git a/test/libsolidity/syntaxTests/parsing/placeholder_in_function_context.sol b/test/libsolidity/syntaxTests/parsing/placeholder_in_function_context.sol new file mode 100644 index 00000000..72546dc0 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/placeholder_in_function_context.sol @@ -0,0 +1,11 @@ +contract c { + function fun() returns (uint r) { + var _ = 8; + return _ + 1; + } +} +// ---- +// Warning: (59-64): Use of the "var" keyword is deprecated. +// Warning: (59-68): The type of this variable was inferred as uint8, which can hold values between 0 and 255. This is probably not desired. Use an explicit type to silence this warning. +// Warning: (17-97): No visibility specified. Defaulting to "public". +// Warning: (17-97): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/struct_definition.sol b/test/libsolidity/syntaxTests/parsing/struct_definition.sol new file mode 100644 index 00000000..0c859e5d --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/struct_definition.sol @@ -0,0 +1,7 @@ +contract test { + uint256 stateVar; + struct MyStructName { + address addr; + uint256 count; + } +} diff --git a/test/libsolidity/syntaxTests/parsing/two_exact_functions.sol b/test/libsolidity/syntaxTests/parsing/two_exact_functions.sol new file mode 100644 index 00000000..0b3dda56 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/two_exact_functions.sol @@ -0,0 +1,9 @@ +// with support of overloaded functions, during parsing, +// we can't determine whether they match exactly, however +// it will throw DeclarationError in following stage. +contract test { + function fun(uint a) returns(uint r) { return a; } + function fun(uint a) returns(uint r) { return a; } +} +// ---- +// DeclarationError: (189-239): Function with same name and arguments defined twice. diff --git a/test/libsolidity/syntaxTests/parsing/visibility_specifiers.sol b/test/libsolidity/syntaxTests/parsing/visibility_specifiers.sol new file mode 100644 index 00000000..4706a26d --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/visibility_specifiers.sol @@ -0,0 +1,17 @@ +contract c { + uint private a; + uint internal b; + uint public c; + uint d; + function f() {} + function f_priv() private {} + function f_public() public {} + function f_internal() internal {} +} +// ---- +// Warning: (58-71): This declaration shadows an existing declaration. +// Warning: (89-104): No visibility specified. Defaulting to "public". +// Warning: (89-104): Function state mutability can be restricted to pure +// Warning: (109-137): Function state mutability can be restricted to pure +// Warning: (142-171): Function state mutability can be restricted to pure +// Warning: (176-209): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/while_loop.sol b/test/libsolidity/syntaxTests/parsing/while_loop.sol new file mode 100644 index 00000000..129b52e1 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/while_loop.sol @@ -0,0 +1,9 @@ +contract test { + function fun(uint256 a) { + while (true) { uint256 x = 1; break; continue; } x = 9; + } +} +// ---- +// Warning: (20-115): No visibility specified. Defaulting to "public". +// Warning: (33-42): Unused function parameter. Remove or comment out the variable name to silence this warning. +// Warning: (20-115): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/types/bool_ops.sol b/test/libsolidity/syntaxTests/types/bool_ops.sol new file mode 100644 index 00000000..91033906 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/bool_ops.sol @@ -0,0 +1,53 @@ +contract C { + function f(bool a, bool b) public pure { + bool c; + // OK + c = !a; + c = !b; + c = a == b; + c = a != b; + c = a || b; + c = a && b; + + // Not OK + c = a > b; + c = a < b; + c = a >= b; + c = a <= b; + c = a & b; + c = a | b; + c = a ^ b; + c = ~a; + c = ~b; + c = a + b; + c = a - b; + c = -a; + c = -b; + c = a * b; + c = a / b; + c = a ** b; + c = a % b; + c = a << b; + c = a >> b; + } +} +// ---- +// TypeError: (231-236): Operator > not compatible with types bool and bool +// TypeError: (250-255): Operator < not compatible with types bool and bool +// TypeError: (269-275): Operator >= not compatible with types bool and bool +// TypeError: (289-295): Operator <= not compatible with types bool and bool +// TypeError: (309-314): Operator & not compatible with types bool and bool +// TypeError: (328-333): Operator | not compatible with types bool and bool +// TypeError: (347-352): Operator ^ not compatible with types bool and bool +// TypeError: (366-368): Unary operator ~ cannot be applied to type bool +// TypeError: (382-384): Unary operator ~ cannot be applied to type bool +// TypeError: (398-403): Operator + not compatible with types bool and bool +// TypeError: (417-422): Operator - not compatible with types bool and bool +// TypeError: (436-438): Unary operator - cannot be applied to type bool +// TypeError: (452-454): Unary operator - cannot be applied to type bool +// TypeError: (468-473): Operator * not compatible with types bool and bool +// TypeError: (487-492): Operator / not compatible with types bool and bool +// TypeError: (506-512): Operator ** not compatible with types bool and bool +// TypeError: (526-531): Operator % not compatible with types bool and bool +// TypeError: (545-551): Operator << not compatible with types bool and bool +// TypeError: (565-571): Operator >> not compatible with types bool and bool diff --git a/test/libsolidity/syntaxTests/types/bytes1_to_uint256.sol b/test/libsolidity/syntaxTests/types/bytes1_to_uint256.sol new file mode 100644 index 00000000..58828a62 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/bytes1_to_uint256.sol @@ -0,0 +1,7 @@ +contract C { + function f() public pure returns(uint256) { + return uint256(bytes1('')); + } +} +// ---- +// TypeError: (76-95): Explicit type conversion not allowed from "bytes1" to "uint256". diff --git a/test/libsolidity/syntaxTests/types/bytes32_to_uint32.sol b/test/libsolidity/syntaxTests/types/bytes32_to_uint32.sol new file mode 100644 index 00000000..77e813ab --- /dev/null +++ b/test/libsolidity/syntaxTests/types/bytes32_to_uint32.sol @@ -0,0 +1,7 @@ +contract C { + function f() public pure returns(uint32) { + return uint32(bytes32('')); + } +} +// ---- +// TypeError: (75-94): Explicit type conversion not allowed from "bytes32" to "uint32". diff --git a/test/libsolidity/syntaxTests/types/bytes_to_contract.sol b/test/libsolidity/syntaxTests/types/bytes_to_contract.sol index 2a3219ec..820dbf9b 100644 --- a/test/libsolidity/syntaxTests/types/bytes_to_contract.sol +++ b/test/libsolidity/syntaxTests/types/bytes_to_contract.sol @@ -1,7 +1,7 @@ contract C { function f() public pure { - C(bytes20(0x1234)); + C(bytes20(uint160(0x1234))); } } // ---- -// TypeError: (64-82): Explicit type conversion not allowed from "bytes20" to "contract C". +// TypeError: (64-91): Explicit type conversion not allowed from "bytes20" to "contract C". diff --git a/test/libsolidity/syntaxTests/types/bytes_to_uint_same_size.sol b/test/libsolidity/syntaxTests/types/bytes_to_uint_same_size.sol new file mode 100644 index 00000000..2963cfd2 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/bytes_to_uint_same_size.sol @@ -0,0 +1,20 @@ +contract C { + function f() public pure returns (uint256) { + return uint256(bytes32(uint256(0))); + } + function g() public pure returns (uint128) { + return uint128(bytes16(uint128(0))); + } + function h() public pure returns (uint64) { + return uint64(bytes8(uint64(0))); + } + function i() public pure returns (uint32) { + return uint32(bytes4(uint32(0))); + } + function j() public pure returns (uint16) { + return uint16(bytes2(uint16(0))); + } + function k() public pure returns (uint8) { + return uint8(bytes1(uint8(0))); + } +} diff --git a/test/libsolidity/syntaxTests/types/index_access_for_bytes.sol b/test/libsolidity/syntaxTests/types/index_access_for_bytes.sol new file mode 100644 index 00000000..f31b4cc0 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/index_access_for_bytes.sol @@ -0,0 +1,6 @@ +contract C { + bytes20 x; + function f(bytes16 b) public view { + b[uint8(x[2])]; + } +} diff --git a/test/libsolidity/syntaxTests/types/uint256_to_bytes1.sol b/test/libsolidity/syntaxTests/types/uint256_to_bytes1.sol new file mode 100644 index 00000000..f70c89ed --- /dev/null +++ b/test/libsolidity/syntaxTests/types/uint256_to_bytes1.sol @@ -0,0 +1,7 @@ +contract C { + function f() public pure returns(bytes1) { + return bytes1(uint256(0)); + } +} +// ---- +// TypeError: (75-93): Explicit type conversion not allowed from "uint256" to "bytes1". diff --git a/test/libsolidity/syntaxTests/types/uint32_to_bytes32.sol b/test/libsolidity/syntaxTests/types/uint32_to_bytes32.sol new file mode 100644 index 00000000..4153c5c3 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/uint32_to_bytes32.sol @@ -0,0 +1,7 @@ +contract C { + function f() public pure returns(bytes32) { + return bytes32(uint32(0)); + } +} +// ---- +// TypeError: (76-94): Explicit type conversion not allowed from "uint32" to "bytes32". |