diff options
author | chriseth <c@ethdev.com> | 2016-08-25 19:25:30 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2016-08-26 06:07:50 +0800 |
commit | 21b6aa92ffe6f5662a234e6e290e842e963917d1 (patch) | |
tree | 688721282aa421c1d9f6fdb92da100dbf020fbad | |
parent | f329d5e772ed4314897c46b67b1459f39838a2cc (diff) | |
download | dexon-solidity-21b6aa92ffe6f5662a234e6e290e842e963917d1.tar dexon-solidity-21b6aa92ffe6f5662a234e6e290e842e963917d1.tar.gz dexon-solidity-21b6aa92ffe6f5662a234e6e290e842e963917d1.tar.bz2 dexon-solidity-21b6aa92ffe6f5662a234e6e290e842e963917d1.tar.lz dexon-solidity-21b6aa92ffe6f5662a234e6e290e842e963917d1.tar.xz dexon-solidity-21b6aa92ffe6f5662a234e6e290e842e963917d1.tar.zst dexon-solidity-21b6aa92ffe6f5662a234e6e290e842e963917d1.zip |
Disallow fallback function to return values.
-rw-r--r-- | docs/contracts.rst | 3 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 2 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 10 |
3 files changed, 14 insertions, 1 deletions
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"( |