mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
fixed new tests
This commit is contained in:
parent
7a7a7dcbb5
commit
675aed1edf
52
libsolidity/Exceptions.cpp
Normal file
52
libsolidity/Exceptions.cpp
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
This file is part of cpp-ethereum.
|
||||||
|
|
||||||
|
cpp-ethereum is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
cpp-ethereum is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @author Christian <c@ethdev.com>
|
||||||
|
* @date 2015
|
||||||
|
* Solidity exception hierarchy.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <libsolidity/Exceptions.h>
|
||||||
|
#include <libsolidity/Utils.h>
|
||||||
|
|
||||||
|
using namespace dev;
|
||||||
|
using namespace dev::solidity;
|
||||||
|
|
||||||
|
Error::Error(Error::Type _type): m_type(_type)
|
||||||
|
{
|
||||||
|
switch(m_type)
|
||||||
|
{
|
||||||
|
case Type::DeclarationError:
|
||||||
|
m_typeName = "Declaration Error";
|
||||||
|
break;
|
||||||
|
case Type::DocstringParsingError:
|
||||||
|
m_typeName = "Docstring Parsing Error";
|
||||||
|
break;
|
||||||
|
case Type::ParserError:
|
||||||
|
m_typeName = "Parser Error";
|
||||||
|
break;
|
||||||
|
case Type::TypeError:
|
||||||
|
m_typeName = "Type Error";
|
||||||
|
break;
|
||||||
|
case Type::Warning:
|
||||||
|
m_typeName = "Warning";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
solAssert(false, "");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
@ -26,7 +26,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <libdevcore/Exceptions.h>
|
#include <libdevcore/Exceptions.h>
|
||||||
#include <libevmasm/SourceLocation.h>
|
#include <libevmasm/SourceLocation.h>
|
||||||
#include <libsolidity/Utils.h>
|
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
{
|
{
|
||||||
@ -51,35 +50,11 @@ public:
|
|||||||
Warning
|
Warning
|
||||||
};
|
};
|
||||||
|
|
||||||
Error(Type _type) : m_type(_type)
|
explicit Error(Type _type);
|
||||||
{
|
|
||||||
switch(m_type)
|
|
||||||
{
|
|
||||||
case Type::DeclarationError:
|
|
||||||
m_typeName = "Declaration Error";
|
|
||||||
break;
|
|
||||||
case Type::DocstringParsingError:
|
|
||||||
m_typeName = "Docstring Parsing Error";
|
|
||||||
break;
|
|
||||||
case Type::ParserError:
|
|
||||||
m_typeName = "Parser Error";
|
|
||||||
break;
|
|
||||||
case Type::TypeError:
|
|
||||||
m_typeName = "Type Error";
|
|
||||||
break;
|
|
||||||
case Type::Warning:
|
|
||||||
m_typeName = "Warning";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
solAssert(false, "");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Type type() const { return m_type; }
|
Type type() const { return m_type; }
|
||||||
std::string const& typeName() const { return m_typeName; }
|
std::string const& typeName() const { return m_typeName; }
|
||||||
|
|
||||||
|
|
||||||
/// helper functions
|
/// helper functions
|
||||||
static Error const* containsErrorOfType(ErrorList const& _list, Error::Type _type)
|
static Error const* containsErrorOfType(ErrorList const& _list, Error::Type _type)
|
||||||
{
|
{
|
||||||
|
@ -23,6 +23,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <libdevcore/Assertions.h>
|
#include <libdevcore/Assertions.h>
|
||||||
|
#include <libsolidity/Exceptions.h>
|
||||||
|
|
||||||
|
namespace dev
|
||||||
|
{
|
||||||
|
namespace solidity
|
||||||
|
{
|
||||||
|
struct InternalCompilerError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Assertion that throws an InternalCompilerError containing the given description if it is not met.
|
/// Assertion that throws an InternalCompilerError containing the given description if it is not met.
|
||||||
#define solAssert(CONDITION, DESCRIPTION) \
|
#define solAssert(CONDITION, DESCRIPTION) \
|
||||||
|
@ -127,11 +127,14 @@ string compile(string _input, bool _optimize)
|
|||||||
{
|
{
|
||||||
bool succ = compiler.compile(_input, _optimize);
|
bool succ = compiler.compile(_input, _optimize);
|
||||||
for (auto const& error: compiler.errors())
|
for (auto const& error: compiler.errors())
|
||||||
|
{
|
||||||
|
auto err = dynamic_pointer_cast<Error const>(error);
|
||||||
errors.append(formatError(
|
errors.append(formatError(
|
||||||
*error,
|
*error,
|
||||||
(dynamic_pointer_cast<Warning const>(error)) ? "Warning" : "Error",
|
(err->type() == Error::Type::Warning) ? "Warning" : "Error",
|
||||||
compiler
|
compiler
|
||||||
));
|
));
|
||||||
|
}
|
||||||
success = succ; // keep success false on exception
|
success = succ; // keep success false on exception
|
||||||
}
|
}
|
||||||
catch (Error const& error)
|
catch (Error const& error)
|
||||||
|
@ -57,12 +57,11 @@ parseAnalyseAndReturnError(string const& _source, bool _reportWarnings = false)
|
|||||||
if(!sourceUnit)
|
if(!sourceUnit)
|
||||||
return make_pair(sourceUnit, nullptr);
|
return make_pair(sourceUnit, nullptr);
|
||||||
|
|
||||||
NameAndTypeResolver resolver({}, errors);
|
std::shared_ptr<GlobalContext> globalContext = make_shared<GlobalContext>();
|
||||||
|
NameAndTypeResolver resolver(globalContext->declarations(), errors);
|
||||||
solAssert(Error::containsOnlyWarnings(errors), "");
|
solAssert(Error::containsOnlyWarnings(errors), "");
|
||||||
resolver.registerDeclarations(*sourceUnit);
|
resolver.registerDeclarations(*sourceUnit);
|
||||||
|
|
||||||
std::shared_ptr<GlobalContext> globalContext = make_shared<GlobalContext>();
|
|
||||||
NameAndTypeResolver resolver(globalContext->declarations());
|
|
||||||
resolver.registerDeclarations(*sourceUnit);
|
resolver.registerDeclarations(*sourceUnit);
|
||||||
|
|
||||||
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
|
for (ASTPointer<ASTNode> const& node: sourceUnit->nodes())
|
||||||
@ -81,7 +80,7 @@ parseAnalyseAndReturnError(string const& _source, bool _reportWarnings = false)
|
|||||||
|
|
||||||
TypeChecker typeChecker(errors);
|
TypeChecker typeChecker(errors);
|
||||||
bool success = typeChecker.checkTypeRequirements(*contract);
|
bool success = typeChecker.checkTypeRequirements(*contract);
|
||||||
BOOST_CHECK(success || !typeChecker.errors().empty());
|
BOOST_CHECK(success || !errors.empty());
|
||||||
|
|
||||||
for (auto const& currentError: errors)
|
for (auto const& currentError: errors)
|
||||||
{
|
{
|
||||||
@ -1119,7 +1118,7 @@ BOOST_AUTO_TEST_CASE(anonymous_event_too_many_indexed)
|
|||||||
contract c {
|
contract c {
|
||||||
event e(uint indexed a, bytes3 indexed b, bool indexed c, uint indexed d, uint indexed e) anonymous;
|
event e(uint indexed a, bytes3 indexed b, bool indexed c, uint indexed d, uint indexed e) anonymous;
|
||||||
})";
|
})";
|
||||||
SOLIDITY_CHECK_ERROR_TYPE(parseAndAnalyseReturnError(text), TypeError);
|
BOOST_CHECK(parseAndAnalyseReturnErrorType(text) == Error::Type::TypeError);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(event_call)
|
BOOST_AUTO_TEST_CASE(event_call)
|
||||||
@ -1282,13 +1281,8 @@ BOOST_AUTO_TEST_CASE(empty_name_return_parameter_with_named_one)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(disallow_declaration_of_void_type)
|
BOOST_AUTO_TEST_CASE(disallow_declaration_of_void_type)
|
||||||
{
|
{
|
||||||
<<<<<<< HEAD
|
|
||||||
char const* sourceCode = "contract c { function f() { var (x) = f(); } }";
|
char const* sourceCode = "contract c { function f() { var (x) = f(); } }";
|
||||||
SOLIDITY_CHECK_ERROR_TYPE(parseAndAnalyseReturnError(sourceCode), TypeError);
|
|
||||||
=======
|
|
||||||
char const* sourceCode = "contract c { function f() { var x = f(); } }";
|
|
||||||
BOOST_CHECK(parseAndAnalyseReturnErrorType(sourceCode) == Error::Type::TypeError);
|
BOOST_CHECK(parseAndAnalyseReturnErrorType(sourceCode) == Error::Type::TypeError);
|
||||||
>>>>>>> 2cd6509... errors instead of exceptions
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(overflow_caused_by_ether_units)
|
BOOST_AUTO_TEST_CASE(overflow_caused_by_ether_units)
|
||||||
@ -2353,8 +2347,6 @@ BOOST_AUTO_TEST_CASE(non_initialized_references)
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
|
||||||
auto b = parseAndAnalyseReturnErrorType(text, true);
|
|
||||||
(void)b;
|
|
||||||
BOOST_CHECK(parseAndAnalyseReturnErrorType(text, true) == Error::Type::Warning);
|
BOOST_CHECK(parseAndAnalyseReturnErrorType(text, true) == Error::Type::Warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2366,7 +2358,7 @@ BOOST_AUTO_TEST_CASE(sha3_with_large_integer_constant)
|
|||||||
function f() { sha3(2**500); }
|
function f() { sha3(2**500); }
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
SOLIDITY_CHECK_ERROR_TYPE(parseAndAnalyseReturnError(text), TypeError);
|
BOOST_CHECK(parseAndAnalyseReturnErrorType(text) == Error::Type::TypeError);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(cyclic_binary_dependency)
|
BOOST_AUTO_TEST_CASE(cyclic_binary_dependency)
|
||||||
@ -2376,7 +2368,7 @@ BOOST_AUTO_TEST_CASE(cyclic_binary_dependency)
|
|||||||
contract B { function f() { new C(); } }
|
contract B { function f() { new C(); } }
|
||||||
contract C { function f() { new A(); } }
|
contract C { function f() { new A(); } }
|
||||||
)";
|
)";
|
||||||
SOLIDITY_CHECK_ERROR_TYPE(parseAndAnalyseReturnError(text), TypeError);
|
BOOST_CHECK(parseAndAnalyseReturnErrorType(text) == Error::Type::TypeError);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(cyclic_binary_dependency_via_inheritance)
|
BOOST_AUTO_TEST_CASE(cyclic_binary_dependency_via_inheritance)
|
||||||
@ -2386,7 +2378,7 @@ BOOST_AUTO_TEST_CASE(cyclic_binary_dependency_via_inheritance)
|
|||||||
contract B { function f() { new C(); } }
|
contract B { function f() { new C(); } }
|
||||||
contract C { function f() { new A(); } }
|
contract C { function f() { new A(); } }
|
||||||
)";
|
)";
|
||||||
SOLIDITY_CHECK_ERROR_TYPE(parseAndAnalyseReturnError(text), TypeError);
|
BOOST_CHECK(parseAndAnalyseReturnErrorType(text) == Error::Type::TypeError);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(multi_variable_declaration_fail)
|
BOOST_AUTO_TEST_CASE(multi_variable_declaration_fail)
|
||||||
@ -2394,7 +2386,7 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration_fail)
|
|||||||
char const* text = R"(
|
char const* text = R"(
|
||||||
contract C { function f() { var (x,y); } }
|
contract C { function f() { var (x,y); } }
|
||||||
)";
|
)";
|
||||||
SOLIDITY_CHECK_ERROR_TYPE(parseAndAnalyseReturnError(text), TypeError);
|
BOOST_CHECK(parseAndAnalyseReturnErrorType(text) == Error::Type::TypeError);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fine)
|
BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fine)
|
||||||
@ -2425,7 +2417,7 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_1)
|
|||||||
function f() { var (a, b, ) = one(); }
|
function f() { var (a, b, ) = one(); }
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
SOLIDITY_CHECK_ERROR_TYPE(parseAndAnalyseReturnError(text), TypeError);
|
BOOST_CHECK(parseAndAnalyseReturnErrorType(text) == Error::Type::TypeError);
|
||||||
}
|
}
|
||||||
BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_2)
|
BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_2)
|
||||||
{
|
{
|
||||||
@ -2435,7 +2427,7 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_2)
|
|||||||
function f() { var (a, , ) = one(); }
|
function f() { var (a, , ) = one(); }
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
SOLIDITY_CHECK_ERROR_TYPE(parseAndAnalyseReturnError(text), TypeError);
|
BOOST_CHECK(parseAndAnalyseReturnErrorType(text) == Error::Type::TypeError);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_3)
|
BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_3)
|
||||||
@ -2446,7 +2438,7 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_3)
|
|||||||
function f() { var (, , a) = one(); }
|
function f() { var (, , a) = one(); }
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
SOLIDITY_CHECK_ERROR_TYPE(parseAndAnalyseReturnError(text), TypeError);
|
BOOST_CHECK(parseAndAnalyseReturnErrorType(text) == Error::Type::TypeError);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_4)
|
BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_4)
|
||||||
@ -2457,7 +2449,7 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_4)
|
|||||||
function f() { var (, a, b) = one(); }
|
function f() { var (, a, b) = one(); }
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
SOLIDITY_CHECK_ERROR_TYPE(parseAndAnalyseReturnError(text), TypeError);
|
BOOST_CHECK(parseAndAnalyseReturnErrorType(text) == Error::Type::TypeError);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_5)
|
BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_5)
|
||||||
@ -2468,7 +2460,7 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_5)
|
|||||||
function f() { var (,) = one(); }
|
function f() { var (,) = one(); }
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
SOLIDITY_CHECK_ERROR_TYPE(parseAndAnalyseReturnError(text), TypeError);
|
BOOST_CHECK(parseAndAnalyseReturnErrorType(text) == Error::Type::TypeError);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_6)
|
BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_6)
|
||||||
@ -2479,7 +2471,7 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_6)
|
|||||||
function f() { var (a, b, c) = two(); }
|
function f() { var (a, b, c) = two(); }
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
SOLIDITY_CHECK_ERROR_TYPE(parseAndAnalyseReturnError(text), TypeError);
|
BOOST_CHECK(parseAndAnalyseReturnErrorType(text) == Error::Type::TypeError);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
@ -997,7 +997,7 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration)
|
|||||||
function g() returns (uint, uint, uint) {}
|
function g() returns (uint, uint, uint) {}
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
BOOST_CHECK_NO_THROW(parseText(text));
|
BOOST_CHECK(successParse(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
Loading…
Reference in New Issue
Block a user