From 5ddbbfcfd8df6c9eeca5ed8010fc7f4cbea33e40 Mon Sep 17 00:00:00 2001 From: Swastik Baranwal Date: Thu, 21 Sep 2023 22:16:26 +0530 Subject: [PATCH] checker: allow using ! and ~ on aliased bool and integral types (#19403) --- vlib/v/checker/checker.v | 6 ++---- vlib/v/tests/alias_bool_not_op_test.v | 7 +++++++ 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 vlib/v/tests/alias_bool_not_op_test.v diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 76b999d4263d51..f302d77b9d02eb 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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 diff --git a/vlib/v/tests/alias_bool_not_op_test.v b/vlib/v/tests/alias_bool_not_op_test.v new file mode 100644 index 00000000000000..04570ea82c0153 --- /dev/null +++ b/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 +}