Disable negation of unsigned constants (Issue: #145)

This commit is contained in:
gingerBill
2017-11-15 21:25:16 +00:00
parent 9bd8bdaa5a
commit e48346a9ee
2 changed files with 7 additions and 1 deletions

View File

@@ -1494,6 +1494,13 @@ void check_unary_expr(Checker *c, Operand *o, Token op, AstNode *node) {
o->mode = Addressing_Invalid;
return;
}
if (op.kind == Token_Sub && is_type_unsigned(type)) {
gbString err_str = expr_to_string(node);
error(op, "A unsigned constant cannot be negated '%s'", err_str);
gb_string_free(err_str);
o->mode = Addressing_Invalid;
return;
}
o->value = exact_unary_operator_value(op.kind, o->value, precision);