From 21b6aa92ffe6f5662a234e6e290e842e963917d1 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 25 Aug 2016 13:25:30 +0200 Subject: Disallow fallback function to return values. --- docs/contracts.rst | 3 ++- libsolidity/analysis/TypeChecker.cpp | 2 ++ test/libsolidity/SolidityNameAndTypeResolution.cpp | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/contracts.rst b/docs/contracts.rst index e9fc4526..85592f5d 100644 --- a/docs/contracts.rst +++ b/docs/contracts.rst @@ -425,7 +425,8 @@ Fallback Function ***************** A contract can have exactly one unnamed function. This function cannot have -arguments and is executed on a call to the contract if none of the other +arguments and cannot return anything. +It is executed on a call to the contract if none of the other functions matches the given function identifier (or if no data was supplied at all). diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 6b2c1cb8..235fcabd 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -94,6 +94,8 @@ bool TypeChecker::visit(ContractDefinition const& _contract) fallbackFunction = function; if (!fallbackFunction->parameters().empty()) typeError(fallbackFunction->parameterList().location(), "Fallback function cannot take parameters."); + if (!fallbackFunction->returnParameters().empty()) + typeError(fallbackFunction->returnParameterList()->location(), "Fallback function cannot return values."); } } if (!function->isImplemented()) diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index e9da390c..f0ab07c5 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -1102,6 +1102,16 @@ BOOST_AUTO_TEST_CASE(fallback_function_with_arguments) BOOST_CHECK(expectError(text) == Error::Type::TypeError); } +BOOST_AUTO_TEST_CASE(fallback_function_with_return_parameters) +{ + char const* text = R"( + contract C { + function() returns (uint) { } + } + )"; + BOOST_CHECK(expectError(text) == Error::Type::TypeError); +} + BOOST_AUTO_TEST_CASE(fallback_function_twice) { char const* text = R"( -- cgit From 9212db305d5b168f4f659b71dcb1d0a52966c59a Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 26 Aug 2016 00:06:27 +0200 Subject: Disable macos. --- .travis.yml | 70 ++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/.travis.yml b/.travis.yml index d787c795..9dc17899 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,6 +47,13 @@ matrix: env: - ZIP_SUFFIX=ubuntu-trusty + - os: linux + dist: trusty + sudo: required + compiler: clang + env: + - ZIP_SUFFIX=ubuntu-trusty-clang + # Documentation target, which generates documentation using Phoenix / ReadTheDocs. - os: linux dist: trusty @@ -77,49 +84,50 @@ matrix: # OS X Mavericks (10.9) # https://en.wikipedia.org/wiki/OS_X_Mavericks # - - os: osx - osx_image: beta-xcode6.2 - env: - - ZIP_SUFFIX=osx-mavericks +# - os: osx +# osx_image: beta-xcode6.2 +# env: +# - ZIP_SUFFIX=osx-mavericks # OS X Yosemite (10.10) # https://en.wikipedia.org/wiki/OS_X_Yosemite # - - os: osx - osx_image: xcode7.1 - env: - # Workaround for "macOS - Yosemite, El Capitan and Sierra hanging?" - # https://github.com/ethereum/solidity/issues/894 - - TRAVIS_TESTS=Off - - ZIP_SUFFIX=osx-yosemite +# - os: osx +# osx_image: xcode7.1 +# env: +# # Workaround for "macOS - Yosemite, El Capitan and Sierra hanging?" +# # https://github.com/ethereum/solidity/issues/894 +# - TRAVIS_TESTS=Off +# - ZIP_SUFFIX=osx-yosemite # OS X El Capitan (10.11) # https://en.wikipedia.org/wiki/OS_X_El_Capitan # - - os: osx - osx_image: xcode7.3 - env: - # The use of Debug config here ONLY for El Capitan is a workaround for "The Heisenbug" - # See https://github.com/ethereum/webthree-umbrella/issues/565 - - TRAVIS_BUILD_TYPE=Debug - # Workaround for "macOS - Yosemite, El Capitan and Sierra hanging?" - # https://github.com/ethereum/solidity/issues/894 - - TRAVIS_TESTS=Off - - ZIP_SUFFIX=osx-elcapitan +# - os: osx +# osx_image: xcode7.3 +# env: +# # The use of Debug config here ONLY for El Capitan is a workaround for "The Heisenbug" +# # See https://github.com/ethereum/webthree-umbrella/issues/565 +# - TRAVIS_BUILD_TYPE=Debug +# # Workaround for "macOS - Yosemite, El Capitan and Sierra hanging?" +# # https://github.com/ethereum/solidity/issues/894 +# - TRAVIS_TESTS=Off +# - ZIP_SUFFIX=osx-elcapitan # macOS Sierra (10.12) # https://en.wikipedia.org/wiki/MacOS_Sierra # - - os: osx - osx_image: xcode8 - env: - # Look like "The Heisenbug" is occurring here too, so we'll do the same workaround. - # See https://travis-ci.org/ethereum/solidity/jobs/150240930 - - TRAVIS_BUILD_TYPE=Debug - # Workaround for "macOS - Yosemite, El Capitan and Sierra hanging?" - # https://github.com/ethereum/solidity/issues/894 - - TRAVIS_TESTS=Off - - ZIP_SUFFIX=macos-sierra +# - os: osx +# osx_image: xcode8 +# env: +# # Look like "The Heisenbug" is occurring here too, so we'll do the same workaround. +# # See https://travis-ci.org/ethereum/solidity/jobs/150240930 +# - TRAVIS_BUILD_TYPE=Debug +# # Workaround for "macOS - Yosemite, El Capitan and Sierra hanging?" +# # https://github.com/ethereum/solidity/issues/894 +# - TRAVIS_TESTS=Off +# - ZIP_SUFFIX=macos-sierra + git: depth: 2 -- cgit From ce42114c4170406f1f7ce67d57429ff3e7b73079 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 26 Aug 2016 00:12:34 +0200 Subject: Fix tests. --- test/libsolidity/SolidityEndToEndTest.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 45f6aec5..f3cd387a 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2529,13 +2529,13 @@ BOOST_AUTO_TEST_CASE(fallback_function) char const* sourceCode = R"( contract A { uint data; - function() returns (uint r) { data = 1; return 2; } + function() { data = 1; } function getData() returns (uint r) { return data; } } )"; compileAndRun(sourceCode); BOOST_CHECK(callContractFunction("getData()") == encodeArgs(0)); - BOOST_CHECK(callContractFunction("") == encodeArgs(2)); + BOOST_CHECK(callContractFunction("") == encodeArgs()); BOOST_CHECK(callContractFunction("getData()") == encodeArgs(1)); } @@ -2544,14 +2544,14 @@ BOOST_AUTO_TEST_CASE(inherited_fallback_function) char const* sourceCode = R"( contract A { uint data; - function() returns (uint r) { data = 1; return 2; } + function() { data = 1; } function getData() returns (uint r) { return data; } } contract B is A {} )"; compileAndRun(sourceCode, 0, "B"); BOOST_CHECK(callContractFunction("getData()") == encodeArgs(0)); - BOOST_CHECK(callContractFunction("") == encodeArgs(2)); + BOOST_CHECK(callContractFunction("") == encodeArgs()); BOOST_CHECK(callContractFunction("getData()") == encodeArgs(1)); } @@ -3002,13 +3002,13 @@ BOOST_AUTO_TEST_CASE(bytes_from_calldata_to_memory) { char const* sourceCode = R"( contract C { - function() returns (bytes32) { + function f() returns (bytes32) { return sha3("abc", msg.data); } } )"; compileAndRun(sourceCode); - bytes calldata1 = bytes(61, 0x22) + bytes(12, 0x12); + bytes calldata1 = FixedHash<4>(dev::sha3("f()")).asBytes() + bytes(61, 0x22) + bytes(12, 0x12); sendMessage(calldata1, false); BOOST_CHECK(m_output == encodeArgs(dev::sha3(bytes{'a', 'b', 'c'} + calldata1))); } @@ -3024,7 +3024,7 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes) contract sender { function sender() { rec = new receiver(); } function() { savedData = msg.data; } - function forward() returns (bool) { rec.call(savedData); return true; } + function forward() returns (bool) { !rec.call(savedData); return true; } function clear() returns (bool) { delete savedData; return true; } function val() returns (uint) { return rec.received(); } receiver rec; @@ -4342,12 +4342,12 @@ BOOST_AUTO_TEST_CASE(external_types_in_calls) y = this.t1(C1(7)); } function t1(C1 a) returns (C1) { return a; } - function() returns (C1) { return C1(9); } + function t2() returns (C1) { return C1(9); } } )"; compileAndRun(sourceCode, 0, "C"); BOOST_CHECK(callContractFunction("test()") == encodeArgs(u256(9), u256(7))); - BOOST_CHECK(callContractFunction("nonexisting") == encodeArgs(u256(9))); + BOOST_CHECK(callContractFunction("t2()") == encodeArgs(u256(9))); } BOOST_AUTO_TEST_CASE(proper_order_of_overwriting_of_attributes) -- cgit