mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Use error message for unary operators.
This commit is contained in:
parent
5f4c91cc6d
commit
755e043a6d
@ -1663,19 +1663,22 @@ bool TypeChecker::visit(UnaryOperation const& _operation)
|
|||||||
else
|
else
|
||||||
_operation.subExpression().accept(*this);
|
_operation.subExpression().accept(*this);
|
||||||
Type const* subExprType = type(_operation.subExpression());
|
Type const* subExprType = type(_operation.subExpression());
|
||||||
Type const* t = type(_operation.subExpression())->unaryOperatorResult(op);
|
TypeResult result = type(_operation.subExpression())->unaryOperatorResult(op);
|
||||||
if (!t)
|
if (!result)
|
||||||
{
|
{
|
||||||
string description = "Unary operator " + string(TokenTraits::toString(op)) + " cannot be applied to type " + subExprType->toString();
|
string description = "Unary operator " + string(TokenTraits::toString(op)) + " cannot be applied to type " + subExprType->toString();
|
||||||
|
if (!result.message().empty())
|
||||||
|
description += ". " + result.message();
|
||||||
if (modifying)
|
if (modifying)
|
||||||
// Cannot just report the error, ignore the unary operator, and continue,
|
// Cannot just report the error, ignore the unary operator, and continue,
|
||||||
// because the sub-expression was already processed with requireLValue()
|
// because the sub-expression was already processed with requireLValue()
|
||||||
m_errorReporter.fatalTypeError(9767_error, _operation.location(), description);
|
m_errorReporter.fatalTypeError(9767_error, _operation.location(), description);
|
||||||
else
|
else
|
||||||
m_errorReporter.typeError(4907_error, _operation.location(), description);
|
m_errorReporter.typeError(4907_error, _operation.location(), description);
|
||||||
t = subExprType;
|
_operation.annotation().type = subExprType;
|
||||||
}
|
}
|
||||||
_operation.annotation().type = t;
|
else
|
||||||
|
_operation.annotation().type = result.get();
|
||||||
_operation.annotation().isConstant = false;
|
_operation.annotation().isConstant = false;
|
||||||
_operation.annotation().isPure = !modifying && *_operation.subExpression().annotation().isPure;
|
_operation.annotation().isPure = !modifying && *_operation.subExpression().annotation().isPure;
|
||||||
_operation.annotation().isLValue = false;
|
_operation.annotation().isLValue = false;
|
||||||
|
@ -6,4 +6,4 @@ contract test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
// TypeError 4907: (97-99): Unary operator - cannot be applied to type uint256
|
// TypeError 4907: (97-99): Unary operator - cannot be applied to type uint256. Unary negation is only allowed for signed integers.
|
||||||
|
Loading…
Reference in New Issue
Block a user