mirror of
https://github.com/vlang/v.git
synced 2025-09-17 03:17:25 -04:00
checker: allow using ! and ~ on aliased bool and integral types (#19403)
This commit is contained in:
parent
c075e44ec1
commit
5ddbbfcfd8
@ -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
|
||||
|
7
vlib/v/tests/alias_bool_not_op_test.v
Normal file
7
vlib/v/tests/alias_bool_not_op_test.v
Normal file
@ -0,0 +1,7 @@
|
||||
type JBoolean = bool
|
||||
|
||||
fn test_alias_not_op() {
|
||||
a := JBoolean(false)
|
||||
b := !a
|
||||
assert b == true
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user