Merge pull request #9033 from a3d4/partfix-5819-add-errorid-to-error-class

Add unique ID to Error class
This commit is contained in:
chriseth 2020-05-28 16:24:47 +02:00 committed by GitHub
commit 65d8b6cf75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 136 additions and 118 deletions

View File

@ -28,8 +28,6 @@ using namespace std;
using namespace solidity;
using namespace solidity::langutil;
ErrorId solidity::langutil::operator"" _error(unsigned long long _error) { return ErrorId{ _error }; }
ErrorReporter& ErrorReporter::operator=(ErrorReporter const& _errorReporter)
{
if (&_errorReporter == this)
@ -62,12 +60,12 @@ void ErrorReporter::warning(
error(_error, Error::Type::Warning, _location, _secondaryLocation, _description);
}
void ErrorReporter::error(ErrorId, Error::Type _type, SourceLocation const& _location, string const& _description)
void ErrorReporter::error(ErrorId _errorId, Error::Type _type, SourceLocation const& _location, string const& _description)
{
if (checkForExcessiveErrors(_type))
return;
auto err = make_shared<Error>(_type);
auto err = make_shared<Error>(_errorId, _type);
*err <<
errinfo_sourceLocation(_location) <<
util::errinfo_comment(_description);
@ -75,12 +73,12 @@ void ErrorReporter::error(ErrorId, Error::Type _type, SourceLocation const& _loc
m_errorList.push_back(err);
}
void ErrorReporter::error(ErrorId, Error::Type _type, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, string const& _description)
void ErrorReporter::error(ErrorId _errorId, Error::Type _type, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, string const& _description)
{
if (checkForExcessiveErrors(_type))
return;
auto err = make_shared<Error>(_type);
auto err = make_shared<Error>(_errorId, _type);
*err <<
errinfo_sourceLocation(_location) <<
errinfo_secondarySourceLocation(_secondaryLocation) <<
@ -102,7 +100,7 @@ bool ErrorReporter::checkForExcessiveErrors(Error::Type _type)
if (m_warningCount == c_maxWarningsAllowed)
{
auto err = make_shared<Error>(Error::Type::Warning);
auto err = make_shared<Error>(4591_error, Error::Type::Warning);
*err << util::errinfo_comment("There are more than 256 warnings. Ignoring the rest.");
m_errorList.push_back(err);
}
@ -116,7 +114,7 @@ bool ErrorReporter::checkForExcessiveErrors(Error::Type _type)
if (m_errorCount > c_maxErrorsAllowed)
{
auto err = make_shared<Error>(Error::Type::Warning);
auto err = make_shared<Error>(4013_error, Error::Type::Warning);
*err << util::errinfo_comment("There are more than 256 errors. Aborting.");
m_errorList.push_back(err);
BOOST_THROW_EXCEPTION(FatalError());

View File

@ -23,6 +23,7 @@
#pragma once
#include <libsolutil/CommonData.h>
#include <libsolutil/Exceptions.h>
#include <liblangutil/Exceptions.h>
#include <liblangutil/SourceLocation.h>
@ -33,17 +34,6 @@
namespace solidity::langutil
{
/**
* Unique identifiers are used to tag and track individual error cases.
* They are passed as the first parameter of error reporting functions.
* Suffix _error helps to find them in the sources.
* The struct ErrorId prevents incidental calls like typeError(3141) instead of typeError(3141_error).
* To create a new ID, one can add 0000_error and then run "python ./scripts/correct_error_ids.py"
* from the root of the repo.
*/
struct ErrorId { unsigned long long error = 0; };
ErrorId operator"" _error(unsigned long long error);
class ErrorReporter
{
public:

View File

@ -26,7 +26,8 @@ using namespace std;
using namespace solidity;
using namespace solidity::langutil;
Error::Error(Type _type, SourceLocation const& _location, string const& _description):
Error::Error(ErrorId _errorId, Type _type, SourceLocation const& _location, string const& _description):
m_errorId(_errorId),
m_type(_type)
{
switch (m_type)
@ -57,8 +58,8 @@ Error::Error(Type _type, SourceLocation const& _location, string const& _descrip
*this << util::errinfo_comment(_description);
}
Error::Error(Error::Type _type, std::string const& _description, SourceLocation const& _location):
Error(_type)
Error::Error(ErrorId _errorId, Error::Type _type, std::string const& _description, SourceLocation const& _location):
Error(_errorId, _type)
{
if (_location.isValid())
*this << errinfo_sourceLocation(_location);

View File

@ -56,6 +56,17 @@ struct InvalidAstError: virtual util::Exception {};
#define astAssert(CONDITION, DESCRIPTION) \
assertThrow(CONDITION, ::solidity::langutil::InvalidAstError, DESCRIPTION)
/**
* Unique identifiers are used to tag and track individual error cases.
* They are passed as the first parameter of error reporting functions.
* Suffix _error helps to find them in the sources.
* The struct ErrorId prevents incidental calls like typeError(3141) instead of typeError(3141_error).
* To create a new ID, one can add 0000_error and then run "python ./scripts/correct_error_ids.py"
* from the root of the repo.
*/
struct ErrorId { unsigned long long error = 0; };
constexpr ErrorId operator"" _error(unsigned long long _error) { return ErrorId{ _error }; }
class Error: virtual public util::Exception
{
public:
@ -69,14 +80,16 @@ public:
Warning
};
explicit Error(
Error(
ErrorId _errorId,
Type _type,
SourceLocation const& _location = SourceLocation(),
std::string const& _description = std::string()
);
Error(Type _type, std::string const& _description, SourceLocation const& _location = SourceLocation());
Error(ErrorId _errorId, Type _type, std::string const& _description, SourceLocation const& _location = SourceLocation());
ErrorId errorId() const { return m_errorId; }
Type type() const { return m_type; }
std::string const& typeName() const { return m_typeName; }
@ -100,6 +113,7 @@ public:
return true;
}
private:
ErrorId m_errorId;
Type m_type;
std::string m_typeName;
};

View File

@ -172,8 +172,7 @@ void StorageOffsets::computeOffsets(TypePointers const& _types)
++slotOffset;
byteOffset = 0;
}
if (slotOffset >= bigint(1) << 256)
BOOST_THROW_EXCEPTION(Error(Error::Type::TypeError) << util::errinfo_comment("Object too large for storage."));
solAssert(slotOffset < bigint(1) << 256 ,"Object too large for storage.");
offsets[i] = make_pair(u256(slotOffset), byteOffset);
solAssert(type->storageSize() >= 1, "Invalid storage size.");
if (type->storageSize() == 1 && byteOffset + type->storageBytes() <= 32)
@ -186,8 +185,7 @@ void StorageOffsets::computeOffsets(TypePointers const& _types)
}
if (byteOffset > 0)
++slotOffset;
if (slotOffset >= bigint(1) << 256)
BOOST_THROW_EXCEPTION(Error(Error::Type::TypeError) << util::errinfo_comment("Object too large for storage."));
solAssert(slotOffset < bigint(1) << 256, "Object too large for storage.");
m_storageSize = u256(slotOffset);
swap(m_offsets, offsets);
}
@ -1776,8 +1774,7 @@ u256 ArrayType::storageSize() const
}
else
size = bigint(length()) * baseType()->storageSize();
if (size >= bigint(1) << 256)
BOOST_THROW_EXCEPTION(Error(Error::Type::TypeError) << util::errinfo_comment("Array too large for storage."));
solAssert(size < bigint(1) << 256, "Array too large for storage.");
return max<u256>(1, u256(size));
}

View File

@ -81,17 +81,19 @@ vector<YulString> AsmAnalyzer::operator()(Literal const& _literal)
{
expectValidType(_literal.type, _literal.location);
if (_literal.kind == LiteralKind::String && _literal.value.str().size() > 32)
typeError(
m_errorReporter.typeError(
3069_error,
_literal.location,
"String literal too long (" + to_string(_literal.value.str().size()) + " > 32)"
);
else if (_literal.kind == LiteralKind::Number && bigint(_literal.value.str()) > u256(-1))
typeError(_literal.location, "Number literal too large (> 256 bits)");
m_errorReporter.typeError(6708_error, _literal.location, "Number literal too large (> 256 bits)");
else if (_literal.kind == LiteralKind::Boolean)
yulAssert(_literal.value == "true"_yulstring || _literal.value == "false"_yulstring, "");
if (!m_dialect.validTypeForLiteral(_literal.kind, _literal.value, _literal.type))
typeError(
m_errorReporter.typeError(
5170_error,
_literal.location,
"Invalid type \"" + _literal.type.str() + "\" for literal \"" + _literal.value.str() + "\"."
);
@ -110,7 +112,8 @@ vector<YulString> AsmAnalyzer::operator()(Identifier const& _identifier)
[&](Scope::Variable const& _var)
{
if (!m_activeVariables.count(&_var))
declarationError(
m_errorReporter.declarationError(
4990_error,
_identifier.location,
"Variable " + _identifier.name.str() + " used before it was declared."
);
@ -118,7 +121,8 @@ vector<YulString> AsmAnalyzer::operator()(Identifier const& _identifier)
},
[&](Scope::Function const&)
{
typeError(
m_errorReporter.typeError(
6041_error,
_identifier.location,
"Function " + _identifier.name.str() + " used without being called."
);
@ -141,7 +145,7 @@ vector<YulString> AsmAnalyzer::operator()(Identifier const& _identifier)
}
if (!found && watcher.ok())
// Only add an error message if the callback did not do it.
declarationError(_identifier.location, "Identifier not found.");
m_errorReporter.declarationError(8198_error, _identifier.location, "Identifier not found.");
}
return {type};
@ -152,7 +156,9 @@ void AsmAnalyzer::operator()(ExpressionStatement const& _statement)
auto watcher = m_errorReporter.errorWatcher();
vector<YulString> types = std::visit(*this, _statement.expression);
if (watcher.ok() && !types.empty())
typeError(_statement.location,
m_errorReporter.typeError(
3083_error,
_statement.location,
"Top-level expressions are not supposed to return values (this expression returns " +
to_string(types.size()) +
" value" +
@ -170,7 +176,8 @@ void AsmAnalyzer::operator()(Assignment const& _assignment)
vector<YulString> types = std::visit(*this, *_assignment.value);
if (types.size() != numVariables)
declarationError(
m_errorReporter.declarationError(
8678_error,
_assignment.location,
"Variable count does not match number of values (" +
to_string(numVariables) +
@ -202,7 +209,9 @@ void AsmAnalyzer::operator()(VariableDeclaration const& _varDecl)
{
vector<YulString> types = std::visit(*this, *_varDecl.value);
if (types.size() != numVariables)
declarationError(_varDecl.location,
m_errorReporter.declarationError(
3812_error,
_varDecl.location,
"Variable count mismatch: " +
to_string(numVariables) +
" variables and " +
@ -217,7 +226,8 @@ void AsmAnalyzer::operator()(VariableDeclaration const& _varDecl)
givenType = types[i];
TypedName const& variable = _varDecl.variables[i];
if (variable.type != givenType)
typeError(
m_errorReporter.typeError(
3947_error,
variable.location,
"Assigning value of type \"" + givenType.str() + "\" to variable of type \"" + variable.type.str() + "."
);
@ -265,7 +275,8 @@ vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)
else if (!m_currentScope->lookup(_funCall.functionName.name, GenericVisitor{
[&](Scope::Variable const&)
{
typeError(
m_errorReporter.typeError(
4202_error,
_funCall.functionName.location,
"Attempt to call variable instead of function."
);
@ -278,12 +289,13 @@ vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)
}))
{
if (!warnOnInstructions(_funCall))
declarationError(_funCall.functionName.location, "Function not found.");
m_errorReporter.declarationError(4619_error, _funCall.functionName.location, "Function not found.");
yulAssert(!watcher.ok(), "Expected a reported error.");
}
if (parameterTypes && _funCall.arguments.size() != parameterTypes->size())
typeError(
m_errorReporter.typeError(
7000_error,
_funCall.functionName.location,
"Function expects " +
to_string(parameterTypes->size()) +
@ -301,7 +313,8 @@ vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)
if (needsLiteralArguments && (*needsLiteralArguments)[i - 1])
{
if (!holds_alternative<Literal>(arg))
typeError(
m_errorReporter.typeError(
9114_error,
_funCall.functionName.location,
"Function expects direct literals as arguments."
);
@ -310,7 +323,8 @@ vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)
_funCall.functionName.name.str() == "dataoffset"
)
if (!m_dataNames.count(std::get<Literal>(arg).value))
typeError(
m_errorReporter.typeError(
3517_error,
_funCall.functionName.location,
"Unknown data object \"" + std::get<Literal>(arg).value.str() + "\"."
);
@ -362,7 +376,7 @@ void AsmAnalyzer::operator()(Switch const& _switch)
/// Note: the parser ensures there is only one default case
if (watcher.ok() && !cases.insert(valueOfLiteral(*_case.value)).second)
declarationError(_case.location, "Duplicate case defined.");
m_errorReporter.declarationError(6792_error, _case.location, "Duplicate case defined.");
}
(*this)(_case.body);
@ -408,7 +422,8 @@ YulString AsmAnalyzer::expectExpression(Expression const& _expr)
{
vector<YulString> types = std::visit(*this, _expr);
if (types.size() != 1)
typeError(
m_errorReporter.typeError(
3950_error,
locationOf(_expr),
"Expected expression to evaluate to one value, but got " +
to_string(types.size()) +
@ -421,7 +436,9 @@ void AsmAnalyzer::expectBoolExpression(Expression const& _expr)
{
YulString type = expectExpression(_expr);
if (type != m_dialect.boolType)
typeError(locationOf(_expr),
m_errorReporter.typeError(
1733_error,
locationOf(_expr),
"Expected a value of boolean type \"" +
m_dialect.boolType.str() +
"\" but got \"" +
@ -440,9 +457,10 @@ void AsmAnalyzer::checkAssignment(Identifier const& _variable, YulString _valueT
{
// Check that it is a variable
if (!holds_alternative<Scope::Variable>(*var))
typeError(_variable.location, "Assignment requires variable.");
m_errorReporter.typeError(2657_error, _variable.location, "Assignment requires variable.");
else if (!m_activeVariables.count(&std::get<Scope::Variable>(*var)))
declarationError(
m_errorReporter.declarationError(
1133_error,
_variable.location,
"Variable " + _variable.name.str() + " used before it was declared."
);
@ -464,9 +482,11 @@ void AsmAnalyzer::checkAssignment(Identifier const& _variable, YulString _valueT
if (!found && watcher.ok())
// Only add message if the callback did not.
declarationError(_variable.location, "Variable not found or variable not lvalue.");
m_errorReporter.declarationError(4634_error, _variable.location, "Variable not found or variable not lvalue.");
if (variableType && *variableType != _valueType)
typeError(_variable.location,
m_errorReporter.typeError(
9547_error,
_variable.location,
"Assigning a value of type \"" +
_valueType.str() +
"\" to a variable of type \"" +
@ -488,7 +508,8 @@ Scope& AsmAnalyzer::scope(Block const* _block)
void AsmAnalyzer::expectValidType(YulString _type, SourceLocation const& _location)
{
if (!m_dialect.types.count(_type))
typeError(
m_errorReporter.typeError(
5473_error,
_location,
"\"" + _type.str() + "\" is not a valid type (user defined types are not yet supported)."
);
@ -497,7 +518,9 @@ void AsmAnalyzer::expectValidType(YulString _type, SourceLocation const& _locati
void AsmAnalyzer::expectType(YulString _expectedType, YulString _givenType, SourceLocation const& _location)
{
if (_expectedType != _givenType)
typeError(_location,
m_errorReporter.typeError(
3781_error,
_location,
"Expected a value of type \"" +
_expectedType.str() +
"\" but got \"" +
@ -524,7 +547,8 @@ bool AsmAnalyzer::warnOnInstructions(evmasm::Instruction _instr, SourceLocation
yulAssert(m_evmVersion.hasBitwiseShifting() == m_evmVersion.hasCreate2(), "");
auto errorForVM = [&](string const& vmKindMessage) {
typeError(
m_errorReporter.typeError(
7079_error,
_location,
"The \"" +
boost::to_lower_copy(instructionInfo(_instr).name)
@ -584,13 +608,3 @@ bool AsmAnalyzer::warnOnInstructions(evmasm::Instruction _instr, SourceLocation
return true;
}
void AsmAnalyzer::typeError(SourceLocation const& _location, string const& _description)
{
m_errorReporter.typeError(7569_error, _location, _description);
}
void AsmAnalyzer::declarationError(SourceLocation const& _location, string const& _description)
{
m_errorReporter.declarationError(9595_error, _location, _description);
}

View File

@ -117,9 +117,6 @@ private:
return warnOnInstructions(_functionCall.functionName.name.str(), _functionCall.functionName.location);
}
void typeError(langutil::SourceLocation const& _location, std::string const& _description);
void declarationError(langutil::SourceLocation const& _location, std::string const& _description);
yul::ExternalIdentifierAccess::Resolver m_resolver;
Scope* m_currentScope = nullptr;
/// Variables that are active at the current point in assembly (as opposed to

View File

@ -81,7 +81,7 @@ bytes BytesUtils::convertBoolean(string const& _literal)
else if (_literal == "false")
return bytes{false};
else
throw Error(Error::Type::ParserError, "Boolean literal invalid.");
throw TestParserError("Boolean literal invalid.");
}
bytes BytesUtils::convertNumber(string const& _literal)
@ -92,7 +92,7 @@ bytes BytesUtils::convertNumber(string const& _literal)
}
catch (std::exception const&)
{
throw Error(Error::Type::ParserError, "Number encoding invalid.");
throw TestParserError("Number encoding invalid.");
}
}
@ -104,7 +104,7 @@ bytes BytesUtils::convertHexNumber(string const& _literal)
}
catch (std::exception const&)
{
throw Error(Error::Type::ParserError, "Hex number encoding invalid.");
throw TestParserError("Hex number encoding invalid.");
}
}
@ -116,7 +116,7 @@ bytes BytesUtils::convertString(string const& _literal)
}
catch (std::exception const&)
{
throw Error(Error::Type::ParserError, "String encoding invalid.");
throw TestParserError("String encoding invalid.");
}
}

View File

@ -30,6 +30,15 @@ namespace solidity::frontend::test
while (false)
class TestParserError: virtual public util::Exception
{
public:
explicit TestParserError(std::string const& _description)
{
*this << util::errinfo_comment(_description);
}
};
/**
* Representation of a notice, warning or error that can occur while
* formatting and therefore updating an interactive function call test.

View File

@ -18,6 +18,7 @@
#include <test/libsolidity/util/TestFileParser.h>
#include <test/libsolidity/util/BytesUtils.h>
#include <test/libsolidity/util/SoltestErrors.h>
#include <test/Common.h>
#include <liblangutil/Common.h>
@ -128,9 +129,9 @@ vector<solidity::frontend::test::FunctionCall> TestFileParser::parseFunctionCall
calls.emplace_back(std::move(call));
}
catch (Error const& _e)
catch (TestParserError const& _e)
{
throw Error{_e.type(), "Line " + to_string(_lineOffset + m_lineNumber) + ": " + _e.what()};
throw TestParserError("Line " + to_string(_lineOffset + m_lineNumber) + ": " + _e.what());
}
}
}
@ -150,8 +151,7 @@ bool TestFileParser::accept(soltest::Token _token, bool const _expect)
bool TestFileParser::expect(soltest::Token _token, bool const _advance)
{
if (m_scanner.currentToken() != _token || m_scanner.currentToken() == Token::Invalid)
throw Error(
Error::Type::ParserError,
throw TestParserError(
"Unexpected " + formatToken(m_scanner.currentToken()) + ": \"" +
m_scanner.currentLiteral() + "\". " +
"Expected \"" + formatToken(_token) + "\"."
@ -187,10 +187,10 @@ pair<string, bool> TestFileParser::parseFunctionSignature()
parameters += parseIdentifierOrTuple();
}
if (accept(Token::Arrow, true))
throw Error(Error::Type::ParserError, "Invalid signature detected: " + signature);
throw TestParserError("Invalid signature detected: " + signature);
if (!hasName && !parameters.empty())
throw Error(Error::Type::ParserError, "Signatures without a name cannot have parameters: " + signature);
throw TestParserError("Signatures without a name cannot have parameters: " + signature);
else
signature += parameters;
@ -207,7 +207,7 @@ FunctionValue TestFileParser::parseFunctionCallValue()
u256 value{ parseDecimalNumber() };
Token token = m_scanner.currentToken();
if (token != Token::Ether && token != Token::Wei)
throw Error(Error::Type::ParserError, "Invalid value unit provided. Coins can be wei or ether.");
throw TestParserError("Invalid value unit provided. Coins can be wei or ether.");
m_scanner.scanNextToken();
@ -216,7 +216,7 @@ FunctionValue TestFileParser::parseFunctionCallValue()
}
catch (std::exception const&)
{
throw Error(Error::Type::ParserError, "Ether value encoding invalid.");
throw TestParserError("Ether value encoding invalid.");
}
}
@ -226,7 +226,7 @@ FunctionCallArgs TestFileParser::parseFunctionCallArguments()
auto param = parseParameter();
if (param.abiType.type == ABIType::None)
throw Error(Error::Type::ParserError, "No argument provided.");
throw TestParserError("No argument provided.");
arguments.parameters.emplace_back(param);
while (accept(Token::Comma, true))
@ -290,7 +290,7 @@ Parameter TestFileParser::parseParameter()
if (accept(Token::Boolean))
{
if (isSigned)
throw Error(Error::Type::ParserError, "Invalid boolean literal.");
throw TestParserError("Invalid boolean literal.");
parameter.abiType = ABIType{ABIType::Boolean, ABIType::AlignRight, 32};
string parsed = parseBoolean();
@ -304,7 +304,7 @@ Parameter TestFileParser::parseParameter()
else if (accept(Token::HexNumber))
{
if (isSigned)
throw Error(Error::Type::ParserError, "Invalid hex number literal.");
throw TestParserError("Invalid hex number literal.");
parameter.abiType = ABIType{ABIType::Hex, ABIType::AlignRight, 32};
string parsed = parseHexNumber();
@ -318,9 +318,9 @@ Parameter TestFileParser::parseParameter()
else if (accept(Token::Hex, true))
{
if (isSigned)
throw Error(Error::Type::ParserError, "Invalid hex string literal.");
throw TestParserError("Invalid hex string literal.");
if (parameter.alignment != Parameter::Alignment::None)
throw Error(Error::Type::ParserError, "Hex string literals cannot be aligned or padded.");
throw TestParserError("Hex string literals cannot be aligned or padded.");
string parsed = parseString();
parameter.rawString += "hex\"" + parsed + "\"";
@ -332,9 +332,9 @@ Parameter TestFileParser::parseParameter()
else if (accept(Token::String))
{
if (isSigned)
throw Error(Error::Type::ParserError, "Invalid string literal.");
throw TestParserError("Invalid string literal.");
if (parameter.alignment != Parameter::Alignment::None)
throw Error(Error::Type::ParserError, "String literals cannot be aligned or padded.");
throw TestParserError("String literals cannot be aligned or padded.");
string parsed = parseString();
parameter.abiType = ABIType{ABIType::String, ABIType::AlignLeft, parsed.size()};
@ -364,7 +364,7 @@ Parameter TestFileParser::parseParameter()
else if (accept(Token::Failure, true))
{
if (isSigned)
throw Error(Error::Type::ParserError, "Invalid failure literal.");
throw TestParserError("Invalid failure literal.");
parameter.abiType = ABIType{ABIType::Failure, ABIType::AlignRight, 0};
parameter.rawBytes = bytes{};
@ -555,10 +555,7 @@ void TestFileParser::Scanner::scanNextToken()
else if (isEndOfLine())
token = make_pair(Token::EOS, "EOS");
else
throw Error(
Error::Type::ParserError,
"Unexpected character: '" + string{current()} + "'"
);
throw TestParserError("Unexpected character: '" + string{current()} + "'");
break;
}
}
@ -651,7 +648,7 @@ string TestFileParser::Scanner::scanString()
str += scanHexPart();
break;
default:
throw Error(Error::Type::ParserError, "Invalid or escape sequence found in string literal.");
throw TestParserError("Invalid or escape sequence found in string literal.");
}
}
else
@ -673,7 +670,7 @@ char TestFileParser::Scanner::scanHexPart()
else if (tolower(current()) >= 'a' && tolower(current()) <= 'f')
value = tolower(current()) - 'a' + 10;
else
throw Error(Error::Type::ParserError, "\\x used with no following hex digits.");
throw TestParserError("\\x used with no following hex digits.");
advance();
if (current() == '"')

View File

@ -25,6 +25,7 @@
#include <liblangutil/Exceptions.h>
#include <test/ExecutionFramework.h>
#include <test/libsolidity/util/SoltestErrors.h>
#include <test/libsolidity/util/TestFileParser.h>
using namespace std;
@ -365,7 +366,7 @@ BOOST_AUTO_TEST_CASE(scanner_hex_values_invalid1)
char const* source = R"(
// f(uint256): "\x" ->
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(scanner_hex_values_invalid2)
@ -383,7 +384,7 @@ BOOST_AUTO_TEST_CASE(scanner_hex_values_invalid3)
char const* source = R"(
// f(uint256): "\xZ" ->
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(scanner_hex_values_invalid4)
@ -391,7 +392,7 @@ BOOST_AUTO_TEST_CASE(scanner_hex_values_invalid4)
char const* source = R"(
// f(uint256): "\xZZ" ->
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_arguments_hex_string)
@ -741,7 +742,7 @@ BOOST_AUTO_TEST_CASE(call_arguments_hex_string_left_align)
char const* source = R"(
// f(bytes): left(hex"4200ef") ->
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_arguments_hex_string_right_align)
@ -749,7 +750,7 @@ BOOST_AUTO_TEST_CASE(call_arguments_hex_string_right_align)
char const* source = R"(
// f(bytes): right(hex"4200ef") ->
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_newline_invalid)
@ -757,7 +758,7 @@ BOOST_AUTO_TEST_CASE(call_newline_invalid)
char const* source = R"(
/
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_invalid)
@ -765,7 +766,7 @@ BOOST_AUTO_TEST_CASE(call_invalid)
char const* source = R"(
/ f() ->
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_signature_invalid)
@ -773,7 +774,7 @@ BOOST_AUTO_TEST_CASE(call_signature_invalid)
char const* source = R"(
// f(uint8,) -> FAILURE
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_arguments_tuple_invalid)
@ -781,7 +782,7 @@ BOOST_AUTO_TEST_CASE(call_arguments_tuple_invalid)
char const* source = R"(
// f((uint8,) -> FAILURE
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_arguments_tuple_invalid_empty)
@ -789,7 +790,7 @@ BOOST_AUTO_TEST_CASE(call_arguments_tuple_invalid_empty)
char const* source = R"(
// f(uint8, ()) -> FAILURE
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_arguments_tuple_invalid_parantheses)
@ -797,14 +798,14 @@ BOOST_AUTO_TEST_CASE(call_arguments_tuple_invalid_parantheses)
char const* source = R"(
// f((uint8,() -> FAILURE
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_ether_value_expectations_missing)
{
char const* source = R"(
// f(), 0)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_arguments_invalid)
@ -812,7 +813,7 @@ BOOST_AUTO_TEST_CASE(call_arguments_invalid)
char const* source = R"(
// f(uint256): abc -> 1
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_arguments_invalid_decimal)
@ -820,7 +821,7 @@ BOOST_AUTO_TEST_CASE(call_arguments_invalid_decimal)
char const* source = R"(
// sig(): 0.h3 ->
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_ether_value_invalid)
@ -828,7 +829,7 @@ BOOST_AUTO_TEST_CASE(call_ether_value_invalid)
char const* source = R"(
// f(uint256), abc : 1 -> 1
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_ether_value_invalid_decimal)
@ -836,7 +837,7 @@ BOOST_AUTO_TEST_CASE(call_ether_value_invalid_decimal)
char const* source = R"(
// sig(): 0.1hd ether ->
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_ether_type_invalid)
@ -844,7 +845,7 @@ BOOST_AUTO_TEST_CASE(call_ether_type_invalid)
char const* source = R"(
// f(uint256), 2 btc : 1 -> 1
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_signed_bool_invalid)
@ -852,7 +853,7 @@ BOOST_AUTO_TEST_CASE(call_signed_bool_invalid)
char const* source = R"(
// f() -> -true
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_signed_failure_invalid)
@ -860,7 +861,7 @@ BOOST_AUTO_TEST_CASE(call_signed_failure_invalid)
char const* source = R"(
// f() -> -FAILURE
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_signed_hex_number_invalid)
@ -868,7 +869,7 @@ BOOST_AUTO_TEST_CASE(call_signed_hex_number_invalid)
char const* source = R"(
// f() -> -0x42
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_arguments_colon)
@ -877,7 +878,7 @@ BOOST_AUTO_TEST_CASE(call_arguments_colon)
// h256():
// -> 1
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_arguments_newline_colon)
@ -887,7 +888,7 @@ BOOST_AUTO_TEST_CASE(call_arguments_newline_colon)
// :
// -> 1
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_arrow_missing)
@ -895,7 +896,7 @@ BOOST_AUTO_TEST_CASE(call_arrow_missing)
char const* source = R"(
// h256() FAILURE
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(call_unexpected_character)
@ -903,7 +904,7 @@ BOOST_AUTO_TEST_CASE(call_unexpected_character)
char const* source = R"(
// f() -> ??
)";
BOOST_REQUIRE_THROW(parse(source), langutil::Error);
BOOST_REQUIRE_THROW(parse(source), TestParserError);
}
BOOST_AUTO_TEST_CASE(constructor)