Restrict unary negation to signed integers.

This commit is contained in:
chriseth
2020-09-17 15:01:53 +02:00
parent e4231b879b
commit aa7a6922e7
6 changed files with 20 additions and 8 deletions
+4 -3
View File
@@ -627,9 +627,10 @@ TypeResult IntegerType::unaryOperatorResult(Token _operator) const
// "delete" is ok for all integer types
if (_operator == Token::Delete)
return TypeResult{TypeProvider::emptyTuple()};
// we allow -, ++ and --
else if (_operator == Token::Sub || _operator == Token::Inc ||
_operator == Token::Dec || _operator == Token::BitNot)
// unary negation only on signed types
else if (_operator == Token::Sub)
return isSigned() ? TypeResult{this} : TypeResult::err("Unary negation is only allowed for signed integers.");
else if (_operator == Token::Inc || _operator == Token::Dec || _operator == Token::BitNot)
return TypeResult{this};
else
return TypeResult::err("");