Skip to content

Commit 5ddbbfc

Browse files
authored
checker: allow using ! and ~ on aliased bool and integral types (#19403)
1 parent c075e44 commit 5ddbbfc

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

vlib/v/checker/checker.v

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4182,12 +4182,10 @@ fn (mut c Checker) prefix_expr(mut node ast.PrefixExpr) ast.Type {
41824182
}
41834183
}
41844184
}
4185-
if node.op == .bit_not && !c.unwrap_generic(right_type).is_int() && !c.pref.translated
4186-
&& !c.file.is_translated {
4185+
if node.op == .bit_not && !right_sym.is_int() && !c.pref.translated && !c.file.is_translated {
41874186
c.type_error_for_operator('~', 'integer', right_sym.name, node.pos)
41884187
}
4189-
if node.op == .not && right_type != ast.bool_type_idx && !c.pref.translated
4190-
&& !c.file.is_translated {
4188+
if node.op == .not && right_sym.kind != .bool && !c.pref.translated && !c.file.is_translated {
41914189
c.type_error_for_operator('!', 'bool', right_sym.name, node.pos)
41924190
}
41934191
// FIXME

vlib/v/tests/alias_bool_not_op_test.v

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type JBoolean = bool
2+
3+
fn test_alias_not_op() {
4+
a := JBoolean(false)
5+
b := !a
6+
assert b == true
7+
}

0 commit comments

Comments
 (0)