mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Use createTypeError everywhere and stream out Location.
This commit is contained in:
parent
094ee44f72
commit
1ae1fc66e2
5
AST.cpp
5
AST.cpp
@ -257,8 +257,7 @@ void Statement::expectType(Expression& _expression, const Type& _expectedType)
|
|||||||
{
|
{
|
||||||
_expression.checkTypeRequirements();
|
_expression.checkTypeRequirements();
|
||||||
if (!_expression.getType()->isImplicitlyConvertibleTo(_expectedType))
|
if (!_expression.getType()->isImplicitlyConvertibleTo(_expectedType))
|
||||||
BOOST_THROW_EXCEPTION(TypeError() << errinfo_sourceLocation(_expression.getLocation())
|
BOOST_THROW_EXCEPTION(_expression.createTypeError("Type not implicitly convertible to expected type."));
|
||||||
<< errinfo_comment("Type not implicitly convertible to expected type."));
|
|
||||||
//@todo provide more information to the exception
|
//@todo provide more information to the exception
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -407,9 +406,7 @@ void FunctionCall::checkTypeRequirements()
|
|||||||
m_type = fun.getReturnParameterList()->getParameters().front()->getType();
|
m_type = fun.getReturnParameterList()->getParameters().front()->getType();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
BOOST_THROW_EXCEPTION(createTypeError("Type does not support invocation."));
|
BOOST_THROW_EXCEPTION(createTypeError("Type does not support invocation."));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemberAccess::checkTypeRequirements()
|
void MemberAccess::checkTypeRequirements()
|
||||||
|
3
AST.h
3
AST.h
@ -57,8 +57,7 @@ public:
|
|||||||
|
|
||||||
Location const& getLocation() const { return m_location; }
|
Location const& getLocation() const { return m_location; }
|
||||||
|
|
||||||
protected:
|
/// Creates a @ref TypeError exception and decorates it with the location of the node and
|
||||||
/// Creates a @ref TypeError exception and decorates it with the current location and
|
|
||||||
/// the given description
|
/// the given description
|
||||||
TypeError createTypeError(std::string const& _description);
|
TypeError createTypeError(std::string const& _description);
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
{
|
{
|
||||||
@ -41,5 +42,11 @@ struct Location
|
|||||||
int end;
|
int end;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Stream output for Location (used e.g. in boost exceptions).
|
||||||
|
inline std::ostream& operator<<(std::ostream& _out, Location const& _location)
|
||||||
|
{
|
||||||
|
return _out << "[" << _location.start << "," << _location.end << ")";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,9 +31,9 @@ namespace dev
|
|||||||
namespace solidity
|
namespace solidity
|
||||||
{
|
{
|
||||||
|
|
||||||
struct ParserError: public virtual Exception {};
|
struct ParserError: virtual Exception {};
|
||||||
struct TypeError: public virtual Exception {};
|
struct TypeError: virtual Exception {};
|
||||||
struct DeclarationError: public virtual Exception {};
|
struct DeclarationError: virtual Exception {};
|
||||||
|
|
||||||
typedef boost::error_info<struct tag_sourcePosition, int> errinfo_sourcePosition;
|
typedef boost::error_info<struct tag_sourcePosition, int> errinfo_sourcePosition;
|
||||||
typedef boost::error_info<struct tag_sourceLocation, Location> errinfo_sourceLocation;
|
typedef boost::error_info<struct tag_sourceLocation, Location> errinfo_sourceLocation;
|
||||||
|
@ -182,8 +182,7 @@ bool ReferencesResolver::visit(UserDefinedTypeName& _typeName)
|
|||||||
StructDefinition* referencedStruct = dynamic_cast<StructDefinition*>(declaration);
|
StructDefinition* referencedStruct = dynamic_cast<StructDefinition*>(declaration);
|
||||||
//@todo later, contracts are also valid types
|
//@todo later, contracts are also valid types
|
||||||
if (referencedStruct == nullptr)
|
if (referencedStruct == nullptr)
|
||||||
BOOST_THROW_EXCEPTION(TypeError() << errinfo_sourceLocation(_typeName.getLocation())
|
BOOST_THROW_EXCEPTION(_typeName.createTypeError("Identifier does not name a type name."));
|
||||||
<< errinfo_comment("Identifier does not name a type name."));
|
|
||||||
_typeName.setReferencedStruct(*referencedStruct);
|
_typeName.setReferencedStruct(*referencedStruct);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user