Skip to content

Commit

Permalink
checker: allow using ! and ~ on aliased bool and integral types (#19403)
Browse files Browse the repository at this point in the history
  • Loading branch information
Delta456 committed Sep 21, 2023
1 parent c075e44 commit 5ddbbfc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 2 additions & 4 deletions vlib/v/checker/checker.v
Expand Up @@ -4182,12 +4182,10 @@ fn (mut c Checker) prefix_expr(mut node ast.PrefixExpr) ast.Type {
}
}
}
if node.op == .bit_not && !c.unwrap_generic(right_type).is_int() && !c.pref.translated
&& !c.file.is_translated {
if node.op == .bit_not && !right_sym.is_int() && !c.pref.translated && !c.file.is_translated {
c.type_error_for_operator('~', 'integer', right_sym.name, node.pos)
}
if node.op == .not && right_type != ast.bool_type_idx && !c.pref.translated
&& !c.file.is_translated {
if node.op == .not && right_sym.kind != .bool && !c.pref.translated && !c.file.is_translated {
c.type_error_for_operator('!', 'bool', right_sym.name, node.pos)
}
// FIXME
Expand Down
7 changes: 7 additions & 0 deletions vlib/v/tests/alias_bool_not_op_test.v
@@ -0,0 +1,7 @@
type JBoolean = bool

fn test_alias_not_op() {
a := JBoolean(false)
b := !a
assert b == true
}

0 comments on commit 5ddbbfc

Please sign in to comment.