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 <libdevcore/Exceptions.h> | ||||
| #include <libevmasm/SourceLocation.h> | ||||
| #include <libsolidity/Utils.h> | ||||
| 
 | ||||
| namespace dev | ||||
| { | ||||
| @ -51,35 +50,11 @@ public: | ||||
| 		Warning | ||||
| 	}; | ||||
| 
 | ||||
| 	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; | ||||
| 		} | ||||
| 	} | ||||
| 	explicit Error(Type _type); | ||||
| 
 | ||||
| 	Type type() const { return m_type; } | ||||
| 	std::string const& typeName() const { return m_typeName; } | ||||
| 
 | ||||
| 
 | ||||
| 	/// helper functions
 | ||||
| 	static Error const* containsErrorOfType(ErrorList const& _list, Error::Type _type) | ||||
| 	{ | ||||
|  | ||||
| @ -23,6 +23,15 @@ | ||||
| #pragma once | ||||
| 
 | ||||
| #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.
 | ||||
| #define solAssert(CONDITION, DESCRIPTION) \ | ||||
|  | ||||
| @ -127,11 +127,14 @@ string compile(string _input, bool _optimize) | ||||
| 	{ | ||||
| 		bool succ = compiler.compile(_input, _optimize); | ||||
| 		for (auto const& error: compiler.errors()) | ||||
| 		{ | ||||
| 			auto err = dynamic_pointer_cast<Error const>(error); | ||||
| 			errors.append(formatError( | ||||
| 				*error, | ||||
| 				(dynamic_pointer_cast<Warning const>(error)) ? "Warning" : "Error", | ||||
| 				(err->type() == Error::Type::Warning) ? "Warning" : "Error", | ||||
| 				compiler | ||||
| 			)); | ||||
| 		} | ||||
| 		success = succ; // keep success false on exception
 | ||||
| 	} | ||||
| 	catch (Error const& error) | ||||
|  | ||||
| @ -57,12 +57,11 @@ parseAnalyseAndReturnError(string const& _source, bool _reportWarnings = false) | ||||
| 		if(!sourceUnit) | ||||
| 			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), ""); | ||||
| 		resolver.registerDeclarations(*sourceUnit); | ||||
| 
 | ||||
| 		std::shared_ptr<GlobalContext> globalContext = make_shared<GlobalContext>(); | ||||
| 		NameAndTypeResolver resolver(globalContext->declarations()); | ||||
| 		resolver.registerDeclarations(*sourceUnit); | ||||
| 
 | ||||
| 		for (ASTPointer<ASTNode> const& node: sourceUnit->nodes()) | ||||
| @ -81,7 +80,7 @@ parseAnalyseAndReturnError(string const& _source, bool _reportWarnings = false) | ||||
| 
 | ||||
| 				TypeChecker typeChecker(errors); | ||||
| 				bool success = typeChecker.checkTypeRequirements(*contract); | ||||
| 				BOOST_CHECK(success || !typeChecker.errors().empty()); | ||||
| 				BOOST_CHECK(success || !errors.empty()); | ||||
| 
 | ||||
| 				for (auto const& currentError: errors) | ||||
| 				{ | ||||
| @ -1119,7 +1118,7 @@ BOOST_AUTO_TEST_CASE(anonymous_event_too_many_indexed) | ||||
| 		contract c { | ||||
| 			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) | ||||
| @ -1282,13 +1281,8 @@ BOOST_AUTO_TEST_CASE(empty_name_return_parameter_with_named_one) | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(disallow_declaration_of_void_type) | ||||
| { | ||||
| <<<<<<< HEAD | ||||
| 	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); | ||||
| >>>>>>> 2cd6509... errors instead of exceptions | ||||
| } | ||||
| 
 | ||||
| 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); | ||||
| } | ||||
| 
 | ||||
| @ -2366,7 +2358,7 @@ BOOST_AUTO_TEST_CASE(sha3_with_large_integer_constant) | ||||
| 			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) | ||||
| @ -2376,7 +2368,7 @@ BOOST_AUTO_TEST_CASE(cyclic_binary_dependency) | ||||
| 		contract B { function f() { new C(); } } | ||||
| 		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) | ||||
| @ -2386,7 +2378,7 @@ BOOST_AUTO_TEST_CASE(cyclic_binary_dependency_via_inheritance) | ||||
| 		contract B { function f() { new C(); } } | ||||
| 		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) | ||||
| @ -2394,7 +2386,7 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration_fail) | ||||
| 	char const* text = R"( | ||||
| 		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) | ||||
| @ -2425,7 +2417,7 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_1) | ||||
| 			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) | ||||
| { | ||||
| @ -2435,7 +2427,7 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_2) | ||||
| 			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) | ||||
| @ -2446,7 +2438,7 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_3) | ||||
| 			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) | ||||
| @ -2457,7 +2449,7 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_4) | ||||
| 			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) | ||||
| @ -2468,7 +2460,7 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_5) | ||||
| 			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) | ||||
| @ -2479,7 +2471,7 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_6) | ||||
| 			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() | ||||
|  | ||||
| @ -997,7 +997,7 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration) | ||||
| 			function g() returns (uint, uint, uint) {} | ||||
| 		} | ||||
| 	)"; | ||||
| 	BOOST_CHECK_NO_THROW(parseText(text)); | ||||
| 	BOOST_CHECK(successParse(text)); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_SUITE_END() | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user